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. Spring课程 Spring入门篇 4-1 Spring bean装配(下)之bean定义及作用域注解实现

    课程链接: 1 概述 2 代码演练 3 代码解析 1 概述 1.1 bean注解相关 a context:component-scan标签使用 问:该标签的作用是什么? 答:该标签作用是支持注解,在x ...

  2. android 扇形菜单

    引言: android中的菜单与windows的菜单没有什么区别,基本就是一个矩形框,如下: 这个菜单有多么能经得住历史的考验我就不多说了!我们再来看看最新有关手机可操作区域的调查 有此可以看出屏幕越 ...

  3. C++ 0x

  4. Android AS升级3.1 编译报错:The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin.

    AndroidStudio升级到3.1后编译报错:The SourceSet ‘instrumentTest’ is not recognized by the Android Gradle Plug ...

  5. mysql启动报错,与selinux相关

    mysql启动报错,与selinux相关 如果遇到报错,可能的情况是 selinux 的关系,可以安装 setroubleshoot-server 工具,使用 sealert -a /var/log/ ...

  6. XFS: Cross Frame Script (跨框架脚本) 攻击。

    一.Cross Frame Script (跨框架脚本) 攻击什么是Cross Frame Script?很简单,做个实验就知道了.把下面的这段HTML代码另存为一个html文件,然后用ie浏览器打开 ...

  7. 实现vmare虚拟机系统随主机开机自动启动

    服务器主机上的虚拟机每次开机要手动启动是很麻烦的事,so,在网上找到一方法让虚拟机随主机开机自动运行:挺方便的,记录下来: 1.操作环境 主机:windows 2003 虚拟机:centos6 2.下 ...

  8. 一起来看看IOS内存泄漏的一个问题

    很多iOS开发的朋友都是比较关心内存泄漏的问题,在实际的开发工作中首先我们需要知道程序有没有内存泄露,然后定位到底是哪行代码出现内存泄露了,这样才能将其修复.最简单的方法当然是借助于专业的检测工具,比 ...

  9. linux上传、下载文件rz、sz命令

    1.介绍 sz命令是利用ZModem协议来从linux服务器传送文件到本地,一次可以传送一个或多个文件.相对应的从本地上传文件到Linux服务器,可以使用rz命令. 2.参数说明 -a,以文本方式传输 ...

  10. 数据结构(C#):图的最短路径问题、(Dijkstra算法)

    今天曾洋老师教了有关于图的最短路径问题,现在对例子进行一个自己的理解和整理: 题目: 要求:变成计算出给出结点V1到结点V8的最短路径 答: 首先呢,我会先通过图先把从V1到V8的各种路径全部计算下来 ...