数学计数原理(Pólya):POJ 1286 Necklace of Beads

Necklace of Beads

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7763   Accepted: 3247

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 around the center of the circular necklace or reflection to the axis of symmetry are all neglected, how many different forms of the necklace are there?

Input

The input has several lines, and each line contains the input data n.

-1 denotes the end of the input file.

Output

The output should contain the output data: Number of different forms, in each line correspondent to the input data.

Sample Input

4
5
-1

Sample Output

21
39    公式是这样子的:

  p是颜色数,这里等于3,可以发现这2*n个置换形成了置换群,满足了群的封闭性。

  那么只要对于每个置换找不动点就好了…… http://www.cnblogs.com/TenderRun/p/5656038.html 循环的部分和这题类似

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5 long long pow[30],phi[30],n,ans;
 6 long long Gcd(long long a,long long b){
 7     return b?Gcd(b,a%b):a;
 8 }
 9 int main(){
10     pow[0]=1;
11     for(int i=1;i<=24;i++)
12         pow[i]=pow[i-1]*3;
13     for(int i=1;i<=24;i++)
14         for(int j=i;j>=1;j--)
15             if(Gcd(i,j)==1)phi[i]+=1;
16     while(scanf("%lld",&n)!=EOF&&n!=-1){
17         if(n==0){printf("0\n");continue;}
18         for(int d=1;d<=n;d++)
19             if(n%d==0)ans+=phi[n/d]*pow[d];
20         if(n%2)ans=(ans+n*pow[(n+1)/2])/2/n;
21         else ans=(ans+n/2*(pow[n/2+1]+pow[n/2]))/2/n;
22         printf("%lld\n",ans);ans=0;
23     }
24 }
25     
				
时间: 2024-10-27 09:24:28

数学计数原理(Pólya):POJ 1286 Necklace of Beads的相关文章

[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

poj 1286 Necklace of Beads &amp; poj 2409 Let it Bead(初涉polya定理)

http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子,要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后相同的属于同一种方法. polya计数. 搜了一篇论文Pólya原理及其应用看了看polya到底是什么东东,它主要计算全部互异的组合的个数.对置换群还是似懂略懂.用polya定理解决问题的关键是找出置换群的个数及哪些置换群,每种置换的循环节数.像这种不同颜色的珠子构成项链的问题可以把N个珠子看成正N边形. Polya定理:(1)设G是p个对象

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 &amp;amp; poj 2409 Let it Bead(初涉polya定理)

http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜了一篇论文Pólya原理及其应用看了看polya究竟是什么东东.它主要计算所有互异的组合的个数.对置换群还是似懂略懂.用polya定理解决这个问题的关键是找出置换群的个数及哪些置换群,每种置换的循环节数.像这样的不同颜色的珠子构成项链的问题能够把N个珠子看成正N边形. Polya定理:(1)设G是p

POJ 1286 Necklace of Beads(项链的珠子)

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

poj 1286 Necklace of Beads

Necklace of Beads 题意:用三种颜色给长度为n(n < 24)的环状手镯涂色,若能通过旋转或翻转得到则表示为同一种,问不同种涂色方案为多少? 思路:纯粹的等价类计算问题: 重点:对旋转和翻转转化为置换操作: 旋转:对间隔的长度进行枚举,即0 <= i < n:这样循环节就为n/gcd(i,n);直接弄成3的幂次方求和即可: 翻转:分奇偶,再求出对称轴的个数和每种情况下循环节的个数即可: 上面求出的a+b只是不动点的个数总和,最后要除以总的置换的个数即2n; #includ

poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)

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

数学计数原理(P&#243;lya,高精度):SGU 294 He&#39;s Circles

He's Circles He wrote n letters "X" and "E" in a circle. He thought that there were 2n possibilities to do it, because each letter may be either "X" or "E". But Qc noticed that some different sequences of letters ca

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