poj1286--Necklace of Beads(置换群+polya计数)

题目链接:点击打开链接

题目大意:给出三种颜色红绿蓝,对一串n个小球的环染色,环可以旋转和翻转,问最终可能有多少不同的染色方案。

首先说明polya计数:

由这个公式,既可以计算出不同的染色方案,那么我们需要求的也就是不同置换的个数,和每一个置换的循环节数

旋转,旋转i个小球的距离,那么会得到0~n-1的置换方案,共有n中,对于旋转i个小球的循环节数为gcd(n,i)

翻转,对于偶数,不经过小球有对称抽有n/2个,每种置换方案有n/2+1个循环节;经过小球的对称轴有n/2个,每种置换方案有n/2个循环节

对于奇数,只存在经过小球的对称轴,有n个,每种方案有n/2+1个循环节

注意:n==0时,输出0

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std ;
#define LL __int64
LL gcd(LL a,LL b) {
    return b == 0 ? a : gcd(b,a%b) ;
}
LL pow(LL x,LL k) {
    if( k == 1 ) return x ;
    LL s = pow(x,k/2) ;
    s = s*s ;
    if( k%2 ) s *= x ;
    return s ;
}
int main() {
    LL n , i , ans , num ;
    while( scanf("%I64d", &n) && n != -1 ) {
        if( n == 0 ){
            printf("0\n") ;
            continue ;
        }
        ans = 0 ;
        for(i = 0 ; i < n ; i++)
            ans += pow(3,gcd(n,i)) ;
        if( n%2 ) {
            ans += n*pow(3,n/2+1) ;
        }
        else {
            ans += n/2*pow(3,n/2) ;
            ans += n/2*pow(3,n/2+1) ;

        }
        printf("%I64d\n", ans/(n*2)) ;
    }
    return 0 ;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-01 14:32:59

poj1286--Necklace of Beads(置换群+polya计数)的相关文章

POJ1286 Necklace of Beads【Polya定理】

题目链接: http://poj.org/problem?id=1286 题目大意: 给定3种颜色的珠子,每种颜色珠子的个数均不限,将这些珠子做成长度为N的项链. 问能做成多少种不重复的项链,最后的结果不会超过int类型数据的表示范围.并且两 条项链相同,当且仅当两条项链通过旋转或是翻转后能重合在一起,且对应珠子的颜 色相同. 解题思路: 这道题和POJ2409是一样的题目,只不过这道题规定了颜色数目. Polya定理的应用.先来看Polya定理. Polya定理:设 G = {a1,a2,-,

poj1286 Necklace of Beads【裸polya】

很裸的polya,不过我看polya看了很久 吉大ACM模板里面也有 #include <cstdio> #include <cmath> #include <iostream> using namespace std; long long gcd(long long a,long long b) { return b==0?a:gcd(b,a%b); } int main() { #ifndef ONLINE_JUDGE //freopen("G:/1.tx

POJ 1286 Necklace of Beads(Polya简单应用)

Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换如果相同就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺快的,代码没什么好说的,裸的Polya,也不需要优化. 1 /************************************************************************* 2 > File Name: POJ1286.cpp 3 > Author: GLSil

【POJ 1286】Necklace of Beads(polya定理)

[POJ 1286]Necklace of Beads(polya定理) Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7550   Accepted: 3145 Description Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n <

hdu 1817 Necklace of Beads(Polya定理)

Necklace of Beads Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 630    Accepted Submission(s): 232 Problem Description Beads of red, blue or green colors are connected together into a circular

HDU 1817Necklace of Beads(置换+Polya计数)

Necklace of Beads Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1817 Description Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 40 ). If

POJ 题目1286 Necklace of Beads(Polya定理)

Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7061   Accepted: 2942 Description Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are pro

【Polya定理】poj1286 Necklace of Beads

Polya定理:设G={π1,π2,π3........πn}是X={a1,a2,a3.......an}上一个置换群,用m中颜色对X中的元素进行涂色,那么不同的涂色方案数为:1/|G|*(mC(π1)+mC(π2)+mC(π3)+...+mC(πk)). 其中C(πk)为置换πk的循环节的个数. Polya定理的基础应用. 你得算出旋转和翻转时,每种置换的循环节数. 旋转时,每种置换的循环节数为gcd(n,i): 翻转时,若n为奇数,共有n个循环节数为n+1>>1的置换, 若n为偶数,共有n

POJ1286 Necklace of Beads

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8263   Accepted: 3452 Description Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are produced by rotation