POJ 1286 Necklaces of Beads (Burnside定理,有限制型)
题目链接: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定理,有限制型)的更多相关文章
- POJ 1286 Necklace of Beads ——Burnside
[题目分析] 题目大意:一个环有n个点,共染三种颜色.问 在旋转和对称的情况下有多少种本质不同的方案数. Burnside直接做. [代码] #include <cstdio> #incl ...
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- poj 2409+2154+2888(Burnside定理)
三道burnside入门题: Burnside定理主要理解置换群置换后每种不动点的个数,然后n种不动点的染色数总和/n为answer. 对于旋转,旋转i个时不动点为gcd(n,i). 传送门:poj ...
- 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 ...
- poj 1286 Necklace of Beads【polya定理+burnside引理】
和poj 2409差不多,就是k变成3了,详见 还有不一样的地方是记得特判n==0的情况不然会RE #include<iostream> #include<cstdio> us ...
- 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. ...
- POJ 1286 Necklace of Beads(Polya定理)
点我看题目 题意 :给你3个颜色的n个珠子,能组成多少不同形式的项链. 思路 :这个题分类就是polya定理,这个定理看起来真的是很麻烦啊T_T.......看了有个人写的不错: Polya定理: ( ...
- poj 1286 Necklace of Beads
这是做的第一道群论题,自然要很水又很裸.注意用long long. 就是用到了两个定理 burnside :不等价方案数=每个置换的不动置换方案数的和 / 置换个数 polya: 一个置换的不动置换方 ...
- poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
随机推荐
- rt: Unknown command 'PATH='
- .net开源工作流引擎ccflow
关于济南驰骋信息技术有限公司的.net开源工作流引擎 驰骋工作流引擎,工作流程管理系统:简称ccflow,驰骋一体化解决方案简称ccport. ccflow是济南驰骋信息技术有限公司向社会提供的一款1 ...
- Java获取当前路径
1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir"));//user ...
- 深入浅出node(4) 异步编程
一)函数式编程基础 二)异步编程的优势和难点 2.1 优势 2.2 难点 2.2.1 异常处理 2.2.2 函数嵌套过深 2.2.3 阻塞 2.2.4 多线程编程 2.2.5 异步转同步 三)异步编程 ...
- CAS学习笔记(三)—— SERVER登录后用户信息的返回
一旦CAS SERVER验证成功后,我们就会跳转到客户端中去.跳转到客户端去后,大家想一想,客户端总要获取用户信息吧,不然客户端是怎么知道登录的是哪个用户.那么客户端要怎么获取用户信息呢? 其实验证成 ...
- 【转】setAnimation和startAnimation区别
http://stackoverflow.com/questions/10909865/setanimation-vs-startanimation-in-android http://blog.cs ...
- UISegmentedControl UISlider
self.view.backgroundColor = [UIColor whiteColor]; //UISegmentedControl 是iOS中的分段控件,事实上是多个button的组合视图, ...
- android 23 启动带2个Categories值的预定义acticity和桌面activity
mainActivity.java package com.sxt.day04_07_twoaction; import android.os.Bundle; import android.app.A ...
- mysql --batch --skip-column-name --execute 使用
mysql -h 127.0.0.1 -P 3306 -u root -p -D test --batch --skip-column-name --execute="select * fr ...
- 计算机体系结构-CPU
NUMA