poj1286--Necklace of Beads(置换群+polya计数)
来源:互联网 发布:淘宝不能登陆 编辑:程序博客网 时间:2024/05/19 08:37
题目链接:点击打开链接
题目大意:给出三种颜色红绿蓝,对一串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 __int64LL 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 ;}
1 0
- poj1286--Necklace of Beads(置换群+polya计数)
- poj1286 Necklace of Beads polya计数
- poj1286 Necklace of Beads(polya定理)
- POJ1286:Necklace of Beads(POLYA定理应用)
- poj1286 Necklace of Beads【裸polya】
- POJ1286 Necklace of Beads【Polya定理】
- poj1286 Necklace of Beads【polya定理】
- POJ1286--Necklace of Beads
- POJ1286 Necklace of Beads
- poj Necklace of Beads 1286 (polya定理)置换群
- poj_1286 Necklace of Beads(置换群Polya定理)
- poj 1286 Necklace of Beads -----polya计数
- poj 1286 Necklace of Beads polya计数
- poj 1286 Necklace of Beads 【polya计数】
- POJ 1286-Necklace of Beads(Polya计数)
- POJ 1286 Necklace of Beads && POJ 2409 Polya计数原理
- POJ 1286 Necklace of Beads(polya计数、burnside定理)
- poj 1286 Necklace of Beads 项链旋转+对称群的polya计数
- java基础:HashMap、HashTable、LinkedHashMap和TreeMap用法和区别
- rtpengine源码结构分析及交互流程
- 分布数数据库事物
- 轻松实现在线word转换成pdf
- 使用Git来部署一个Web站点笔记
- poj1286--Necklace of Beads(置换群+polya计数)
- NSDictionary 或者NSArray(NSMutableArray) ==>> NSData ==>> NSString (Json):
- hadoop下实现kmeans一
- POJ 3083 Children of the Candy Corn(搜索)
- 搜索引擎:MapReduce实战----倒排索引
- [Java Web]Mac OSX中MyEclipse的Console输出乱码的问题
- -Dmaven.multiModuleProjectDirectory system propery is not set.
- netty4源码分析——写操作
- MySQL 面试题目