设为首页 加入收藏

TOP

POJ 题目1286 Necklace of Beads(Polya定理)
2015-11-21 01:03:23 来源: 作者: 【 】 浏览:2
Tags:POJ 题目 1286 Necklace 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 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

Source

Xi'an 2002

?

题目大意:

n个珠子串成一个圆,用三种颜色去涂色。问一共有多少种不同的涂色方法。

不同的涂色方法被定义为:如果这种涂色情况翻转,旋转不与其他情况相同就为不同。

?

解题思路:

Polya定理模版题。

对于顺时针长度为i的旋转,为pow(3,__gcd(n,i);

对于翻转,当为奇数时,有:n*pow(3.0,n/2+1);

当为偶数时,有:n/2*pow(3.0,n/2)+n/2*pow(3.0,n/2+1);

?

一共有2*n种情况,最后要除以2*n


ac代码

?

#include
  
   
#include
   
     #include
    
      int gcd(int a,int b) { if(a
     
      

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 3087 Shuffle'm Up 下一篇POJ - 1159 - Palindrome (LCS +..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: