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 are all neglected, how many different forms of the necklace are there? 

Input

The input has several lines, and each line contains the input data n. 
-1 denotes the end of the input file. 

Output

The output should contain the output data: Number of different forms, in each line correspondent to the input data.
 
题目大意:用3种颜色的珠子串一条项链,旋转或对称后相同的视为同一种方案,问n个珠子有多少种方案。
思路:比较基础的Polya原理题。
对于置换,旋转有n种方案。而对称也有n种方案。
旋转的n种方案有多少循环节暴力一下即可,好像用数论的方法也行反制我不会。
而对称,要分奇数偶数的情况讨论
偶数的情况:关于两点之间连线的对称,有n/2+1个循环节;关于相邻两点之间连线的垂直平分线对称,有n/2个循环节(显然的>_<)
奇数的情况:关于某点和中心所连直线对称,有(n+1)/2个循环节。
PS:在n比较小的时候置换会重复,但答案是对的,这大概只是偶然?
PS:n=0的时候输出0,不要问我为什么我也不知道为什么,果然这种远古级别的题目提交之前应该先看看DISCUSS……
 
代码(0MS):
 #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原理)的更多相关文章

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

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

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

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

  3. POJ 1286 Necklace of Beads(Polya简单应用)

    Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...

  4. 数学计数原理(Pólya):POJ 1286 Necklace of Beads

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7763   Accepted: 3247 ...

  5. POJ 1286 Necklace of Beads(项链的珠子)

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7874   Accepted: 3290 ...

  6. 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 ...

  7. 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. ...

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

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

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

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

随机推荐

  1. ubuntu下安装与卸载qt的方法

    http://blog.csdn.net/huyisu/article/details/24014407 ubuntu下安装与卸载qt的方法 分类: linux 2014-04-18 14:20 18 ...

  2. sphinx续5-主索引增量索引和实时索引

    原文件地址:http://blog.itpub.net/29806344/viewspace-1400942/ 在数据库数据非常庞大的时候,而且实时有新的数据插入,如果我们不更新索引,新的数据就sea ...

  3. 超级管理员登录后如果连续XX分钟没有操作再次操作需要重新登录

    首先在设置session页面时 session_start(); session("name",$adminname); //加入session时间 time() session( ...

  4. [LeetCode]题解(python):036-Valid Sudoku

    题目来源 https://leetcode.com/problems/valid-sudoku/ etermine if a Sudoku is valid, according to: Sudoku ...

  5. 【转】Android性能优化之布局优化篇

     转自:http://blog.csdn.net/feiduclear_up/article/details/46670433 Android性能优化之布局优化篇 分类: andorid 开发2015 ...

  6. js 事件监听封装

    var eventUtil={//添加句柄 //element,节点 //type,事件类型 //handler,函数 addHandler:function(element,type,handler ...

  7. iOS系统版本简介

    iOS系统版本简介 ⽬目前iOS设备所⽀支持的最主流操作系统是iOS6,⼤大概占了93%,⽽而使 ⽤用iOS5的iOS设备⼤大概占6%,剩下的只有1%.( 根据苹果的官⽅方数据 ) 从iOS1到现在的 ...

  8. Android大图片裁剪终极解决方案(上:原理分析)

    转载声明:Ryan的博客文章欢迎您的转载,但在转载的同时,请注明文章的来源出处,不胜感激! :-)  http://my.oschina.net/ryanhoo/blog/86842 约几个月前,我正 ...

  9. UIScorlView 循环滚动

    - (void) createAdScrollView { _view = [[UIView alloc] initWithFrame:CGRectMake(, , WIDTH, )]; [self. ...

  10. IIS+WebMatrix 做 PHP 遇到的问题总结

    1. URL Binding Failure Webmatrix 解决办法: 用管理员权限运行 WebMatrix 并且 改 Port. 我反正是随便输入了一个 Port 就成功了, 默认的是 610 ...