Necklace of Beads
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 9162   Accepted: 3786

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.

Sample Input

4
5
-1

Sample Output

21
39

题意:n个珠子串成一个圆,用三种颜色去涂色,问一共有多少种不同的涂色方法(不同的涂色方法被定义为:如果这种涂色情况翻转,旋转不与其他情况相同就为不同。)

思路:这道题其实就是一个最简单的板子题。要想明白Polya定理首先要知道置换,置换群和轮换的概念,可以参考这里(用例子很好理解)。

项链可以进行旋转和翻转。

翻转:如果n是奇数,则存在n中置换,每种置换包含n/2+1种循环(即轮换)。

如果n是偶数,如果对称轴过顶点,则存在n/2种置换,每种置换包含n/2种循环(即轮换)

如果对称轴不过顶点,则存在n/2种置换,每种置换包含n/2+1种循环(即轮换)

旋转:n个点顺时针或者逆时针旋转i个位置的置换,轮换个数为gcd(n,i)

代码:

 #include"bits/stdc++.h"
#define db double
#define ll long long
#define vec vector<ll>
#define mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
//#define rep(i, x, y) for(int i=x;i<=y;i++)
#define rep(i, n) for(int i=0;i<n;i++)
const int N = 1e3+ ;
const int mod = 1e9 + ;
//const int MOD = mod - 1;
const int inf = 0x3f3f3f3f;
const db PI = acos(-1.0);
const db eps = 1e-;
using namespace std;
ll gcd(ll x,ll y){
return y==?x:gcd(y,x%y);
}
ll qpow(ll x,ll n)
{
ll ans=;
x%=mod;
while(n){
if(n&) ans=ans*x;
x=x*x;
n>>=;
}
return ans;
} int main()
{
ll n;
while(cin>>n&&n!=-)
{
if(!n) puts("");
else
{
ll ans=;
for(ll i=;i<=n;i++) ans+=qpow(3ll,gcd(n,i));
if(n&) ans+=qpow(3ll,n/+)*n;
else ans+=qpow(3ll,n/+)*(n/)+qpow(3ll,n/)*(n/);
pl(ans//n);
}
}
return ;
}

POJ 1286 Pólya定理的更多相关文章

  1. poj 1286 polya定理

    Necklace of Beads Description Beads of red, blue or green colors are connected together into a circu ...

  2. poj 2409(polya定理模板)

    题意:给你n种颜色和m个小球,问你有多少种不同的方案! 分析:作为模板.. 代码实现: #include <iostream> #include <cstdio> #inclu ...

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

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

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

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

  5. POJ 2409 Let it Bead(Polya定理)

    点我看题目 题意 :给你c种颜色的n个珠子,问你可以组成多少种形式. 思路 :polya定理的应用,与1286差不多一样,代码一改就可以交....POJ 1286题解 #include <std ...

  6. POJ 2409 Let it Bead:置换群 Polya定理

    题目链接:http://poj.org/problem?id=2409 题意: 有一串n个珠子穿起来的项链,你有k种颜色来给每一个珠子染色. 问你染色后有多少种不同的项链. 注:“不同”的概念是指无论 ...

  7. POJ 1286 【POLYA】

    题意: 给你三种颜色的珠子,每次给你N,问在旋转,翻转之后视作相同的情况下,能组成多少种不同的项链. 思路: 让我们借这道题拯救一下我对POLYA定理的理解... sigma(m^(gcd(i,n)) ...

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

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

  9. POJ 2409 Let it Bead (Polya定理)

    题意 用k种颜色对n个珠子构成的环上色,旋转翻转后相同的只算一种,求不等价的着色方案数. 思路 Polya定理 X是对象集合{1, 2, --, n}, 设G是X上的置换群,用M种颜色染N种对象,则不 ...

随机推荐

  1. Xxy 的车厢调度

    有 一 个 火 车 站 , 铁 路 如 图 所 示 ,每辆火车从 A 驶入, 再从 B 方向驶出,同时它的车厢可以重新组合.假设 从 A 方向驶来的火车有 n 节(n<=1000) ,分别按照顺 ...

  2. 线程队列queue

    队列queue 队列用于线程之间安全的信息交换 队列和列表的区别:队列里的信息get()后就没了,而列表获取数据则是copy,原列表里的值还在 使用前先实例化队列 q = queue.Queue(ma ...

  3. 关于 IntelliJ IDEA 的Maven 版本修改

    Project Structure->Project里Project sdk以及project language level Project Structure->Modules里Sour ...

  4. vscode:快速生成html的方法

    第一步:在空文档中输入! 第二步:按下tab键. 以上

  5. zendstudio 汉化

    http://archive.eclipse.org/technology/babel/index.php http://www.eclipse.org/babel/downloads.php 注册码 ...

  6. Arduino-串口函数Serial

    串口是Arduino与其它设备进行通信的接口,我们需要很好的掌握它的使用.Arduino串口使用相关的函数共有10个(随着版本的升级,新版本加入了更多,具体请参见官网:http://www.ardui ...

  7. CFG的定义

    最近在CMU上NLP,好吧 对于见了很多年的CFG(Context-Free Grammar)发现又搞不懂是什么了 教材上写的是: mathematical system for modeling c ...

  8. IOS 自定义Operation(下载功能)

    一个下载操作就交给一个HMDownloadOperation对象 HMDownloadOperation.h / .m @class HMDownloadOperation; @protocol HM ...

  9. PASCAL VOC数据集分析

    http://blog.csdn.net/zhangjunbob/article/details/52769381

  10. Spring boot 实现高吞吐量异步处理(适用于高并发场景)

    技术要点 org.springframework.web.context.request.async.DeferredResult<T> 示例如下: 1.   新建Maven项目  asy ...