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. 简述AFN(AFNetWorking 2.X)的实现分析和简单使用【转】

    [转载] Axc注:版本为AFNetWorking 2.6    3.0需要修改大部分对象 一:声明本 人以前一直是使用ASI网络请求类库的.最近才开始了解使用AFNetworing这个类库.网上也肯 ...

  2. php YAF

    Yaf 的特点: 用C语言开发的PHP框架, 相比原生的PHP, 几乎不会带来额外的性能开销. 所有的框架类, 不需要编译, 在PHP启动的时候加载, 并常驻内存. 更短的内存周转周期, 提高内存利用 ...

  3. Java 并发:Executors 和线程池

    让我们开始来从入门了解一下 Java 的并发编程. 本文主要介绍如何开始创建线程以及管理线程池,在 Java 语言中,一个最简单的线程如下代码所示: Runnable runnable = new R ...

  4. 关于网站的UV分析

    一:准备 1.统计的维度 guid tracktime provice 2.key与value的设定 key:date+provice_guid value:NullWritable 3.案例分析 表 ...

  5. X-UA-Compatible是神马

    X-UA-Compatible是神马 X-UA-Compatible是IE8的一个专有<meta>属性,它告诉IE8采用何种IE版本去渲染网页,在html的<head>标签中使 ...

  6. Architecture of a Highly Scalable NIO-Based Server

    一. thread-per-connection The thread-per-connection approach uses an exclusive worker thread for each ...

  7. php--如何解决网站分页导致的SEO问题

    如何解决网站分页导致的SEO问题 分页(pagination)是一种自动分页机制,可以将移动Web窗体中的内容分割成一组组较小的页进行呈现,以适合于特定的设备,该机制还呈现可用于浏览到其他页的用户界面 ...

  8. NGINX原理分析 之 SLAB分配机制

    1 引言 众所周知,操作系统使用伙伴系统管理内存,不仅会造成大量的内存碎片,同时处理效率也较低下.SLAB是一种内存管理机制,其拥有较高的处理效率,同时也 有效的避免内存碎片的产生,其核心思想是预分配 ...

  9. 不允许修改SQLserver2008r2表中字段的属性问题

    SQLserver2008r2修改表中字段的属性时弹出 点击工具->选项,取消阻止保存要求重新创建表的更改

  10. 深入理解Redis主键失效原理及实现机制

    http://blog.jobbole.com/71095/ 对于缓存失效,不同的缓存有不同的处理机制,可以说是大同中有小异,作者通过对Redis 文档与相关源码的仔细研读,为大家详细剖析了 Redi ...