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. Chrome浏览器正常,IE下界面却乱了

    背景:项目实战中总会遇到一些小问题,IE特别多 Chrome浏览器页面正常,IE下界面就乱了 原因分析 1.首先想到的是代码有米有问题呢?主要指的是兼容性 2.兼容性没有问题,那我们打开IE的开发工具 ...

  2. 账户密码提示 jq简单事件

    $(".username").focus(function(){ if($(this).val()=="请输入用户名"){ $(this).val(" ...

  3. fd_set实现原理

    fd_set是一个结构 /* The fd_set member is required to be an array of longs. */ typedef long int __fd_mask; ...

  4. MVC 默认路由 Areas

    1.使用重名controller 在asp.net mvc2以后的版本里面,有了area(区域的概念),这为我们开发中提供了不少方便的地方,但是很不凑巧,若是存在多个重名的controller就会发生 ...

  5. Java—常量和变量

    关键字 Java中有特殊用途的词被称为关键字,关键字服务大小写. 标识符 标识符是用于给java程序中的变量.类.方法等命名的符号. 标识符的几条规则: 由字母.数字.下划线(_).美元符号($)组成 ...

  6. 在sql中如何把一列的值拆分成多列

  7. [译文]PHP千年虫(y2k compliance)

    时钟将我们无情地逼近2000年的最后一年,第二年厄运塞耶斯都预言前所未有的电脑故障在每一个可以想象的领域.通常被称为2000年问题,或千年虫,这种 情况很容易解释.程序解释两位在形成XX日期19 XX ...

  8. 【PHP 模板引擎】Prototype 原型版发布!

    在文章的开头,首先要向一直关注我的人说声抱歉!因为原本是打算在前端框架5.0发布之后,就立马完成 PHP 模板引擎的初版.但我没能做到,而且一直拖到了15年元旦才完成,有很严重的拖延症我很惭愧,再次抱 ...

  9. 字符串反转,栈模拟(ZOJ1151)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=151 这里可以用栈模拟,也可以用STL,reverse();函数. 但 ...

  10. CentOS 6下PXE+Kickstart无人值守安装操作系统

    一.简介1.1 什么是PXEPXE(Pre-boot Execution Environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作 ...