POJ 1286-Necklace of Beads(Polya计数)
来源:互联网 发布:淘宝企业店铺税收问题 编辑:程序博客网 时间:2024/05/23 18:52
题目地址:POJ 1286
题意:n个珠子串成一个圆,用三种颜色去涂色。问一共有多少种不同的涂色方法(不同的涂色方法被定义为:如果这种涂色情况翻转,旋转不与其他情况相同就为不同。)
思路:Polya定理第一发,这道题其实就是一个最简单的板子题。要想明白Polya定理首先要知道置换,置换群和轮换的概念,可以参考这里(用例子很好理解)。
项链可以进行旋转和翻转。
翻转:如果n是奇数,则存在n中置换,每种置换包含n/2+1种循环(即轮换)。
如果n是偶数,如果对称轴过顶点,则存在n/2种置换,每种置换包含n/2种循环(即轮换)
如果对称轴不过顶点,则存在n/2种置换,每种置换包含n/2+1种循环(即轮换)
旋转:n个点顺时针或者逆时针旋转i个位置的置换,轮换个数为gcd(n,i)
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>//#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const double pi= acos(-1.0);const double esp=1e-6;LL gcd(LL a,LL b) { while(b!=0) { LL r=b; b=a%b; a=r; } return a;}LL modxp(LL a,LL b) { LL res=1; while(b!=0) { if(b&1) res*=a; a=a*a; b>>=1; } return res;}int main() { LL n,i; LL ans; while(~scanf("%lld",&n)) { if(n==-1) break; if(!n){ puts("0"); continue; }//不要掉了这种情况 ans=0; for(i=1; i<=n; i++) ans+=modxp(3,gcd(n,i)); if(n&1) { ans+=modxp(3,n/2+1)*n; } else { ans+=modxp(3,n/2+1)*(n/2); ans+=modxp(3,n/2)*(n/2); } printf("%lld\n",ans/(n*2)); } return 0;}
1 0
- 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定理
- 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(Polya原理)
- POJ 1286 Necklace of Beads Polya .
- POJ 1286 Necklace of Beads (Polya)
- POJ 2409 Let it Bead / 1286 Necklace of Beads Polya 计数
- [ACM] POJ 1286 Necklace of Beads (Polya计数,直接套公式)
- poj 1286 Necklace of Beads 项链旋转+对称群的polya计数
- !codeforces 399D Painting The Wall-概率dp
- 代码手写UI,xib和StoryBoard间的博弈
- 链接和URL的生成 — UrlHelper V.S. HtmlHelper
- javascript 判断空格(包括空格、tab键等)
- 关于如何求解数独问题
- POJ 1286-Necklace of Beads(Polya计数)
- UVa 11806 Cheerleaders 拉拉队
- leetcode 057 —— Insert Interval
- SPOJ NUMTSN NUMTSN - 369 Numbers(数位dp)
- [leetcode] 219. Contains Duplicate II
- 一个网站基本完工后测试的几个步骤
- 题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高?
- C编译: 动态连接库 (.so文件)
- Html5学习之表单提交