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.txt","r",stdin);
		//freopen("G:/2.txt","w",stdout);
	#endif
	long long p[33];
	p[0]=1;
	for(long long i=1;i<=24;i++)
	{
		p[i]=p[i-1]*3;
		//cout<<p[i]<<endl;
	}
	long long res=0;
	long long s;
	while(cin>>s)
	{
        if(s==-1)
            break;
        if(s==0)
        {
            cout<<"0\n";
            continue;
        }
		long long res=s&1?s*p[s/2+1]:(s/2)*(p[s/2]+p[s/2+1]);
		for(long long k=1;k<=s;k++)
		{
			res+=p[gcd(k,s)];
		}
		res/=2*s;
		cout<<res<<'\n';
	}
    return 0;
}

poj1286 Necklace of Beads【裸polya】

时间: 2024-11-06 16:57:55

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,-,

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 <

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

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

【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

Necklace of Beads (polya定理的引用)

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 around the center of the circular necklace or reflection to the axis of symmetry are all neglec

[ACM] POJ 1286 Necklace of Beads (Polya计数,直接套公式)

Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6547   Accepted: 2734 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