hdu 1817 Necklace of Beads(Polya定理)

题目链接:hdu 1817 Necklace of Beads

这题的弱化版:传送门

 1 #include<bits/stdc++.h>
 2 #define F(i,a,b) for(int i=a;i<=b;++i)
 3 using namespace std;
 4 typedef long long ll;
 5
 6 int t,n,m,cas;
 7
 8 ll mypow(ll a,ll k){
 9     ll an=1;
10     while(k){
11         if(k&1)an=an*a;
12         k>>=1,a=a*a;
13     }
14     return an;
15 }
16
17 int main(){
18     n=3;
19     while(cin>>m)
20     {
21         if(m==0){puts("0");continue;}
22         if(m==-1)break;
23         ll ans=0;
24         F(i,1,m)ans+=mypow(n,__gcd(i,m));
25         if((m&1))ans=(ans+m*mypow(n,m/2+1));
26         else ans=(ans+m/2*mypow(n,m/2+1)+m/2*mypow(n,m/2));
27         ans=ans/m/2;
28         cout<<ans<<endl;
29     }
30     return 0;
31 }

时间: 2024-10-01 21:41:23

hdu 1817 Necklace of Beads(Polya定理)的相关文章

hdu 1817 Necklace of Beads (polya)

Necklace of Beads Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1049    Accepted Submission(s): 378 Problem Description Beads of red, blue or green colors are connected together into a circula

hdu 1817 Necklace of Beads(Polya定理)

Necklace of Beads Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 630    Accepted Submission(s): 232 Problem Description Beads of red, blue or green colors are connected together into a circular

[ACM] POJ 1286 Necklace of Beads (Polya计数,直接套公式)

Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6547   Accepted: 2734 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 pro

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

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 ar

HDU 3923 Invoker 【裸Polya 定理】

参考了http://blog.csdn.net/ACM_cxlove?viewmode=contents           by---cxlove 的模板 对于每一种染色,都有一个等价群,例如旋转,翻转等.我们将每一种变换转换成一个置换群,通过置换群得到的都是等价的染色方案 最终我们要求的是非等价的染色方案数. 在Burnside定理中给出,在每一种置换群也就是等价群中的数量和除以置换群的数量,即非等价的着色数等于在置换群中的置换作用下保持不变的着色平均数. 我们以POJ 2409 Let i

hdu 5080 Colorful Toy(计算几何+polya定理)

题意:n个点m条边,给边染色,有c种颜色,求染色方案有几种(旋转重合的方案记作同一种): 思路:旋转染色方案数用polya定理解决,每个置换群计算一次: 由计算几何的方法控制旋转,由sin,cos的有理数性质得,分别计算旋转0,90,180,270的方案数: #pragma comment(linker,"/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<c

POJ 题目1286 Necklace of 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 pro

poj 1286 Necklace of Beads &amp; poj 2409 Let it Bead(初涉polya定理)

http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子,要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后相同的属于同一种方法. polya计数. 搜了一篇论文Pólya原理及其应用看了看polya到底是什么东东,它主要计算全部互异的组合的个数.对置换群还是似懂略懂.用polya定理解决问题的关键是找出置换群的个数及哪些置换群,每种置换的循环节数.像这种不同颜色的珠子构成项链的问题可以把N个珠子看成正N边形. Polya定理:(1)设G是p个对象

【POJ 1286】Necklace of Beads(polya定理)

[POJ 1286]Necklace of Beads(polya定理) Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7550   Accepted: 3145 Description Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n <