uva11255 - Necklace 项链旋转翻转 置换
来源:互联网 发布:流行朋克知乎 编辑:程序博客网 时间:2023/09/28 02:03
Once upon a time, three girls - Winnie, Grace and Bonnie - owned a large number of pearls. However, each of them only had a single color of pearls. Winnie had white pearls, Grace had grey pearls and Bonnie had black pearls. One day, after a long discussion, they decided to make necklaces using the pearls. They are interested in knowing how many patterns can be formed using a certain number of pearls of each color, and have asked you to solve this problem for them.
Note that rotating or flipping over a necklace cannot produce a different kind of necklace. i.e. The following figure shows three equivalent necklaces.

The following figure shows all possible necklaces formed by 3 white pearls, 2 grey pearls and 1 black pearl.

Input
The input begins with an integer N (≤ 2500) which indicates the number of test cases followed. Each of the following test cases consists of three non-negative integersa,b, c, where 3 ≤a +b + c ≤ 40.
Output
For each test case, print out the number of different necklaces that formed by a white pearls, b grey pearls and c black pearls in a single line.
Sample input
2
3 2 1
2 2 2
3 2 1
2 2 2
Sample output
6
11
11
有三种颜色的珠子,能组成多少种项链,旋转翻转算一种。
设珠子编号0-n。
旋转:如果逆时针旋转i颗珠子的间距,则珠子0,i,2i...构成一个循环。循环节n/gcd(i,n),有gcd(i,n)个这样的循环。
翻转:当n为奇数,对称轴有n条,每条对称轴形成(n-1)/2个长度为2的循环和1个长度为1的循环。当n为偶数,有两种对称轴。穿过珠子的对称轴有n/2条,各形成n/2-1个窗独为2的循环和2个长度为1的循环。不穿过珠子的对称轴有n/2条,各形成n/2个长度为2的循环。
这里每种颜色的珠子不是无穷的,因为一个循环中要用同一种颜色,所以还要判断是否满足。
#include<iostream>#include<algorithm>#include<queue>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<set>#include<map>#define INF 0x3f3f3f3f#define MAXN 45#define MAXM 1500#define MOD 1000000007#define MAXNODE 8*MAXN#define eps 1e-9using namespace std;typedef long long LL;int T;LL C[MAXN][MAXN];void getC(){ for(int i=0;i<MAXN;i++){ C[i][0]=C[i][i]=1; for(int j=1;j<i;j++) C[i][j]=C[i-1][j]+C[i-1][j-1]; }}int gcd(int a,int b){ return a%b?gcd(b,a%b):b;}LL cal(int a,int b,int c,int l,int m){ if(a<0||b<0||c<0) return 0; if(a%l||b%l||c%l) return 0; a/=l; b/=l; return C[m][a]*C[m-a][b]; //从m个循环中选a个用颜色a,从剩下的中选b个用颜色b,再剩下的用颜色c}int main(){ freopen("in.txt","r",stdin); getC(); scanf("%d",&T); while(T--){ int a,b,c; scanf("%d%d%d",&a,&b,&c); int n=a+b+c; LL ans=0; //旋转 for(int i=0;i<n;i++){ int l=gcd(i,n); ans+=cal(a,b,c,n/l,l); } //翻转 //n为奇数,分别选一种颜色的珠子穿过对称轴,这个珠子可以有n个位置 if(n%2){ ans+=cal(a-1,b,c,2,n/2)*n; ans+=cal(a,b-1,c,2,n/2)*n; ans+=cal(a,b,c-1,2,n/2)*n; } //n为偶数 else{ ans+=cal(a,b,c,2,n/2)*(n/2); //对称轴不穿过珠子,有n/2种对称轴 //对称轴穿过2种颜色珠子,有n种对称轴 ans+=cal(a-1,b-1,c,2,n/2-1)*n; ans+=cal(a-1,b,c-1,2,n/2-1)*n; ans+=cal(a,b-1,c-1,2,n/2-1)*n; //对称轴穿过2个同样颜色的珠子,有n/2种对称轴 ans+=cal(a-2,b,c,2,n/2-1)*(n/2); ans+=cal(a,b-2,c,2,n/2-1)*(n/2); ans+=cal(a,b,c-2,2,n/2-1)*(n/2); } printf("%lld\n",ans/(2*n)); } return 0;}
0 0
- uva11255 - Necklace 项链旋转翻转 置换
- uva11255 Necklace
- POJ 1286-Necklace of Beads(Polya定理-旋转+翻转 串项链)
- UVA11255 necklace (polya定理)
- uva10054-The Necklace(项链)
- 【SDOI2013 necklace】项链
- poj 1286 Necklace of Beads 项链旋转+对称群的polya计数
- uva 11255 - Necklace(置换)
- Broken Necklace破碎的项链
- Broken Necklace破碎的项链
- Broken Necklace 坏掉的项链
- POJ 2409-Let it Bead(Polya定理-旋转+翻转 串项链)
- UVa Problem 10054 The Necklace (项链)
- usaco1.1.4 Broken Necklace破碎的项链
- USACO1.1.4 Broken Necklace(破碎的项链)
- USACO1.1.4 Broken Necklace 破碎的项链
- Broken Necklace-----破碎的项链----USACO---C1S1
- bzoj 1789: [Ahoi2008]Necklace Y型项链
- C++ Primer 【第四版】第八章 标准IO库
- Spring Aop实例
- 模板方法模式
- awk学习笔记
- 黑马程序员——网络编程
- uva11255 - Necklace 项链旋转翻转 置换
- HDU 3832 Earth Hour (最短路)
- C++ Primer 【第四版】第九章 顺序容器
- HDU 2298-Run(二分)
- window8.1 metro应用开发 之helloworld
- 黑马程序员--------------面向对象
- linux视频学习网站
- Android的Intent和IntentFilter应用说明一例
- 写给曾经的自己现在的自己和未来的自己