Necklace of Beads
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7451   Accepted: 3102

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
题解:给出红,绿,蓝3种颜色 的n个珠子,求能够组成多少个不同的项链。 (旋转 和 翻转后 相同的属于同一个项链)
看了好久大神的代码还是不太理解;暂时的理解是,对于每个循环节里的元素都有k中染色方案,所以是k^c(f);
现在只需要找出所有循环节的种数就好了;当然翻转和旋转循环节是不同的,翻转和旋转均有n种;所有种数加完要除以2n

Polya定理:

(1)设G是p个对象的一个置换群,用k种颜色给这p个对象,若一种染色方案在群G的作用下变为另一种方案,则这两个方案当作是同一种方案,这样的不同染色方案数为

(2)对于N个珠子的项链,共有n种旋转置换和n种翻转置换。

对于旋转置换:每种置换的循环节数c(fi) = gcd(n,i),(i为一次转过多少个珠子)

对于翻转置换:如果n为奇数,共有n种翻转置换,每种置换的循环节数均为c(f) = n/2 + 1;              如果n为偶数,分两种情况 <1> 从空白处穿对称轴,则轴两边各有n/2个对象,得到c(f) = n/2;

<2> 从两个对象上穿对称轴,则轴两边各有n/2-2个对象,得到c(f) = n/2 + 1。

代码:

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
typedef long long LL;
int gcd(int a,int b){return b==?a:gcd(b,a%b);}
int main(){
int n;
while(~SI(n),n!=-){
LL ans=;
if(!n){
puts("");continue;
}
for(int i=;i<=n;i++)
ans+=pow(,gcd(i,n));
ans+=n*(n&?pow(,n/+):(pow(,n/)/+pow(,n/+)/));
printf("%lld\n",ans/(*n));
}
return ;
}

Necklace of Beads(polya计数)的更多相关文章

  1. hdu 1817 Necklace of Beads (polya)

    Necklace of Beads Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

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

      Description Beads of red, blue or green colors are connected together into a circular necklace of ...

  3. POJ1286 Necklace of Beads(Polya定理)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9359   Accepted: 3862 Description Beads ...

  4. poj1286 Necklace of Beads—— Polya定理

    题目:http://poj.org/problem?id=1286 真·Polya定理模板题: 写完以后感觉理解更深刻了呢. 代码如下: #include<iostream> #inclu ...

  5. Necklace of Beads(polya定理)

    http://poj.org/problem?id=1286 题意:求用3种颜色给n个珠子涂色的方案数.polya定理模板题. #include <stdio.h> #include &l ...

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

    Necklace of Beads Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

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

    Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...

  8. hdu 1817 Necklace of Beads(Polya定理)

    Necklace of Beads Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

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

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7763   Accepted: 3247 ...

随机推荐

  1. Delphi反汇编内部字符串处理函数不完全列表

    Delphi反汇编内部字符串处理函数/过程不完全列表 名称 参数 返回值 作用 等价形式 / 备注 _PStrCat EAX :目标字符串 EDX :源字符串 EAX 连接两个 Pascal 字符串 ...

  2. Map map=new HashMap(); 为什么是这样

    Map是接口,hashMap是Map的一种实现.接口不能被实例化. Map map=new HashMap(); 就是将map实例化成一个hashMap.这样做的好处是调用者不需要知道map具体的实现 ...

  3. 如何优化pom依赖项?

    Maven工程通过pom.xml里的<dependency>来定义依赖项.当然,我们不会少定义依赖项,否则编译不通过.不过,如果我们多定义了依赖项虽然不会造成灾难,但可能会造成一些问题,比 ...

  4. -DDEBUG编译标记

    想必大家都有利用输出函数如printf来帮助我们调试程序的经历,这是一种比较原始的程序调试辅助方法,在Linux下也可以为我们所用.不过这种方法有一个明显的缺点,就是在调试完后我们必须注释或删除掉这些 ...

  5. Tengine笔记3:Nginx的反向代理和健康状态检查

    通常代理服务器只用于处理内部网络对Intenet的请求,客户端必须通过代理服务器把本来要发送到Web服务器上的请求通过代理服务器分发给Web服务器,Web服务器响应时再通过代理服务器把响应发给客户端: ...

  6. 【最大点独立集】【poj1419】【Graph Coloring】

    题意: 最多能选取多少点,没有边相连. 解法: 取反图,求最大团 代码: #include<cstdio> #include<cstring> #include<iost ...

  7. CSS学习笔记(1):选择器

    一.元素选择器 HTML文档元素就是最基本的选择器 如: <!DOCTYPE html> <html lang="en"> <head> < ...

  8. SQL 时间格式化函数

    1 取值后格式化 {0:d}小型:如2005-5-6 {0:D}大型:如2005年5月6日 {0:f}完整型 2 当前时间获取 DateTime.Now.ToShortDateString 3 取值中 ...

  9. sql 添加字段备注和查看已添加表的备注

    虽然avl树和红黑树在数据搜索和排序方面都是有效的数据结构,但是都显得特别麻烦,跳跃表就显得特别简单,虽然简单 不影响他性能,在平均情况下,其插入.删除.查找数据时间复杂度都是O(log(N)),其最 ...

  10. openwrt 家用备忘