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 ...
随机推荐
- ubuntu下安装与卸载qt的方法
http://blog.csdn.net/huyisu/article/details/24014407 ubuntu下安装与卸载qt的方法 分类: linux 2014-04-18 14:20 18 ...
- sphinx续5-主索引增量索引和实时索引
原文件地址:http://blog.itpub.net/29806344/viewspace-1400942/ 在数据库数据非常庞大的时候,而且实时有新的数据插入,如果我们不更新索引,新的数据就sea ...
- 超级管理员登录后如果连续XX分钟没有操作再次操作需要重新登录
首先在设置session页面时 session_start(); session("name",$adminname); //加入session时间 time() session( ...
- [LeetCode]题解(python):036-Valid Sudoku
题目来源 https://leetcode.com/problems/valid-sudoku/ etermine if a Sudoku is valid, according to: Sudoku ...
- 【转】Android性能优化之布局优化篇
转自:http://blog.csdn.net/feiduclear_up/article/details/46670433 Android性能优化之布局优化篇 分类: andorid 开发2015 ...
- js 事件监听封装
var eventUtil={//添加句柄 //element,节点 //type,事件类型 //handler,函数 addHandler:function(element,type,handler ...
- iOS系统版本简介
iOS系统版本简介 ⽬目前iOS设备所⽀支持的最主流操作系统是iOS6,⼤大概占了93%,⽽而使 ⽤用iOS5的iOS设备⼤大概占6%,剩下的只有1%.( 根据苹果的官⽅方数据 ) 从iOS1到现在的 ...
- Android大图片裁剪终极解决方案(上:原理分析)
转载声明:Ryan的博客文章欢迎您的转载,但在转载的同时,请注明文章的来源出处,不胜感激! :-) http://my.oschina.net/ryanhoo/blog/86842 约几个月前,我正 ...
- UIScorlView 循环滚动
- (void) createAdScrollView { _view = [[UIView alloc] initWithFrame:CGRectMake(, , WIDTH, )]; [self. ...
- IIS+WebMatrix 做 PHP 遇到的问题总结
1. URL Binding Failure Webmatrix 解决办法: 用管理员权限运行 WebMatrix 并且 改 Port. 我反正是随便输入了一个 Port 就成功了, 默认的是 610 ...