题目链接:http://vjudge.net/problem/viewProblem.action?id=11117

就是利用每种等价情形算出置换节之后算组合数

#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath> using namespace std;
#define lson o<<1
#define rson o<<1|1
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
#define INF 200000000 typedef long long ll;
ll qpow(ll a,int k){
ll ans=;
while(k>){
if(k&)ans*=a;
a*=a;
k>>=;
}
return ans;
}
int gcd(int a,int b){
if(a==)return b;
return gcd(b%a,a);
}
ll rotation(int n){
ll rot=;
for(int i=;i<=n;i++){
rot+=qpow(3LL,gcd(i,n));
}
return rot;
}
ll reflection(int n){
ll ref=;
if(n&){
int cir=n/+;
ref=qpow(3LL,cir)*n;
}else{
ref=(ll)(n/)*qpow(3LL,n/);
ref+=(ll)(n/)*qpow(3LL,+n/);
}
return ref;
}
int main(){
int n;
while(~scanf("%d",&n) && n+){
ll ans;
if(!n)ans=;
else ans=(rotation(n)+reflection(n))/(*n);
printf("%I64d\n",ans);
}
return ;
}

POJ 1286 Necklaces of Beads (Burnside定理,有限制型)的更多相关文章

  1. POJ 1286 Necklace of Beads ——Burnside

    [题目分析] 题目大意:一个环有n个点,共染三种颜色.问 在旋转和对称的情况下有多少种本质不同的方案数. Burnside直接做. [代码] #include <cstdio> #incl ...

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

    http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...

  3. poj 2409+2154+2888(Burnside定理)

    三道burnside入门题: Burnside定理主要理解置换群置换后每种不动点的个数,然后n种不动点的染色数总和/n为answer. 对于旋转,旋转i个时不动点为gcd(n,i). 传送门:poj ...

  4. poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>

    链接:http://poj.org/problem?id=1286 http://poj.org/problem?id=2409 #include <cstdio> #include &l ...

  5. poj 1286 Necklace of Beads【polya定理+burnside引理】

    和poj 2409差不多,就是k变成3了,详见 还有不一样的地方是记得特判n==0的情况不然会RE #include<iostream> #include<cstdio> us ...

  6. poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)

    题目:http://poj.org/problem?id=2409 题意:用k种不同的颜色给长度为n的项链染色 网上大神的题解: 1.旋转置换:一个有n个旋转置换,依次为旋转0,1,2,```n-1. ...

  7. POJ 1286 Necklace of Beads(Polya定理)

    点我看题目 题意 :给你3个颜色的n个珠子,能组成多少不同形式的项链. 思路 :这个题分类就是polya定理,这个定理看起来真的是很麻烦啊T_T.......看了有个人写的不错: Polya定理: ( ...

  8. poj 1286 Necklace of Beads

    这是做的第一道群论题,自然要很水又很裸.注意用long long. 就是用到了两个定理 burnside :不等价方案数=每个置换的不动置换方案数的和 / 置换个数 polya: 一个置换的不动置换方 ...

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

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

随机推荐

  1. eclipse常见错误

    1.The superclass “javax.servlet.http.httpservlet” is not found in the build path 原因:未添加server librar ...

  2. Delphi 编写的Web Service

      一编写服务程序 第一步:File----->New----->Other------>WebServices----->Soap Server Application选择I ...

  3. MT9M021/MT9M031总结

    MT9M021/MT9m031在低光照度下和捕捉移动场景有非常优异的表现,属于近红外摄像头, S1: Aptina's MT9M021/MT9M031 sensor is capable of a m ...

  4. [原]ubuntu下制作openstack-havana源

    ubuntu下可以用apt-mirror下载openstack的源: 1.安装apt-mirror: apt-get install apt-mirror 2.配置/etc/apt/mirror.li ...

  5. 深入hibernate的三种状态【转载】

    这篇文章写得很好,举了很多例子. http://www.cnblogs.com/xiaoluo501395377/p/3380270.html

  6. Sicily1153-马的周游问题:启发式搜索

    代码地址: https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1153.c 题目如下: 1153. 马的周游问题 C ...

  7. 爬虫技术浅析 | WooYun知识库

    爬虫技术浅析 | WooYun知识库 爬虫技术浅析 好房通ERP | 房产中介软件最高水准领导者 undefined

  8. 部署war包到Tomcat

    1. 开发给到一个war包,假设叫 a-b-c.war. 2. 打开Tomcat安装路径 ,假设是“D:\Tomcat\apache-tomcat-7.0.68”,然后进入到 webapps文件夹. ...

  9. dp poj 1080 Human Gene Functions

    题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...

  10. 并查集hdu1232

    Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道 ...