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. (开发)ESLint - 代码规范

    参考文档:http://eslint.cn/ ESLint 是在 ECMAScript/JavaScript 代码中识别和报告模式匹配的工具,它的目标是保证代码的一致性和避免错误.在许多方面,它和 J ...

  2. JS的定时到底有多不准

    博客逐步迁移到,独立博客,原文地址,http://www.woniubi.cn/js_hide_tab_setinterval/ 我们一直都在说,JS的定时非常的不准确,但是很少有人去验证他,今天我就 ...

  3. Java笔记 —— 继承

    Java笔记 -- 继承 h2{ color: #4ABCDE; } a{ text-decoration: none!important; } a:hover{ color: red !import ...

  4. lottie使用

    dependencies { implementation 'com.airbnb.android:lottie:2.5.5' } 动画素材地址:https://www.lottiefiles.com ...

  5. sudoer解释

    /etc/sudoer ## Sudoers allows particular users to run various commands as ## the root user, without ...

  6. April 26 2017 Week 17 Wednesday

    We read the world wrong and say that it deceives us. 我们把世界看错了,反而说它欺骗了我们. It is not a cakewalk to see ...

  7. Altium_Designer-怎么将“原理图的更改”更新到“pcb图”?

    打开原理图,直击菜单栏>>Design,选择第一项,>>Update PCB Document...在弹出的对话框里面选择执行更改即可将原理图更新到工程下面对应的PCB.也可以 ...

  8. IOS 设置定时器,执行方法

    //设置定时器(1秒后跳到一下题) [self performSelector:@selector(nextQuestion) withObject:nil afterDelay:1.0];

  9. 并查集,是否成树,Poj(1308)

    思路: 对于每一条新的边的两个端点,是否是属于一颗树,要是的话,就不是一颗树.否则,就合并. 这里要注意的是,不能是森林,我这里WA了两次了.只不过在最后,查看每个节点的祖先是否是同一个就可以了. # ...

  10. 2018.8.25 JVM

    一.JVM内存区域 Java虚拟机在运行时,会把内存空间分为若干个区域,根据<Java虚拟机规范(Java SE 7 版)>的规定,Java虚拟机所管理的内存区域分为如下部分: 方法区 堆 ...