POJ 1286 Necklace of Beads(Polya原理)
Description

Input
-1 denotes the end of the input file.
Output
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long LL; const int MAXN = ; int n, m = ;
bool vis[MAXN]; LL power(LL x, int p) {
LL ret = ;
while(p) {
if(p & ) ret *= x;
x *= x;
p >>= ;
}
return ret;
} LL solve() {
LL ans = ;
for(int step = ; step < n; ++step) {
memset(vis, , sizeof(vis));
int t = ;
for(int i = ; i < n; ++i) {
if(vis[i]) continue;
for(int j = i; !vis[j]; j = (j + step) % n) vis[j] = true;
++t;
}
ans += power(m, t);
}
if(n & ) ans += n * power(m, (n + ) / );
else ans += (n / ) * power(m, n / + ) + (n / ) * power(m, n / );
return n == ? : ans / ( * n);
} int main() {
while(scanf("%d", &n) != EOF) {
if(n == -) break;
printf("%I64d\n", solve());
}
}
POJ 1286 Necklace of Beads(Polya原理)的更多相关文章
- poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- POJ 1286 Necklace of Beads(Polya简单应用)
Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...
- 数学计数原理(Pólya):POJ 1286 Necklace of Beads
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7763 Accepted: 3247 ...
- POJ 1286 Necklace of Beads(项链的珠子)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7874 Accepted: 3290 ...
- 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 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【polya定理+burnside引理】
和poj 2409差不多,就是k变成3了,详见 还有不一样的地方是记得特判n==0的情况不然会RE #include<iostream> #include<cstdio> us ...
随机推荐
- hadoop与云技术、云计算混肴澄清
本文引用自:http://www.aboutyun.com/blog-61-248.html 一.初学者问题: 请教个问题在实际的生成环境里面,数据源产生的地方部署Hadoop,还是需要程序把数据给迁 ...
- 国外it网站收集
1.http://news.com.com/2.http://www.zdnet.com/3.http://www.salon.com/tech/index.html4.http://www.brin ...
- zepto-创建dom
在使用zepto时,为了使得ajax请求回来的数据添加到页面上之后,不至于失去所绑定的事件. 我一般会采用$()创建dom元素节点,然后添加所需要的class和html等等一系列的样式,最基本的是$( ...
- magento去掉add to cmpre和email to friend
修改:\app\design\frontend\default\blanco\template\catalog\product下list.phtml 和app\design\frontend\defa ...
- Windows-004-显示文件的扩展名
此文主要讲述 Windows 7 下如何显示文件的扩展名,敬请亲们参阅.若有不足之处,敬请大神指正,不胜感激! 通常安装好 Win7 后,文件的扩展名默认是不显示的,如下所示: 点击工具栏中的 组织, ...
- raspberry 烧写镜像到SD卡
刚开始接触树莓派,需要烧写系统镜像到SD卡,网上找了些资料,记录于此. raspberry镜像下载: https://www.raspberrypi.org/downloads/ 烧写工具: wid3 ...
- 与Perl兼容的正则表达式函数
<?php $str = "abc_ABC_123abc"; $patt = '/^abc(.*?)abc$/'; //有一个模式单元就会多一个存储 $arr = null; ...
- Linux命令行–理解Linux文件权限(转)
6.1.1 /etc/passwd文件 /etc/passwd:包含系统用户账户列表以及每个用户的基本配置信息 每个条目有七个字段,每个字段用冒号隔开 登录用户名 用户密码 用户账户的UID 用户账户 ...
- APICloud提供适用于命令行的开发工具,开发更具极客精神!
APICloud近期大动作不断,上周刚刚支持Atom编辑器,并推出核心开发工具库.本周又为开发者提供了一款超轻便的新开发工具--CLI工具! 操作系统: Mac/Windows/Linux nodej ...
- Power-BI 关于2016年7月份深圳一手房房价分析报表 腾讯课堂开课啦
上周我们的公开课讲了全国房地产投资开发的情况,通过对时间.区域等多维度的分析,透析了全国房地产开发的投资情况.这周呢,我们就全国一线城市的房价,选取了深圳作为分析对象,对深圳一手房房价进行一 ...