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粘贴图片直接上传

    背景 截图或页面复制图片,可以直接通过Ctrl+v 粘贴上传图片 原理 操作:复制(截图)=>粘贴=>上传 监听粘贴事件=>获取剪贴板里的内容=>发请求上传 浏览器:Chrom ...

  2. css颜色 hsla 和line-gradient

    h 表示色调 从0-360 s 饱和度  0 - 100% l 亮度    0 -100% a 透明度  0-1

  3. [C#]为什么Interface里的成员不能使用static修饰?

    首先引用MSDN里的原文 Interface members are automatically public, and they can't include any access modifiers ...

  4. RESTful API设计基本原则

    REST四个基本原则:1.使用HTTP动词:GET POST PUT DELETE:2.无状态连接,服务器端不应保存过多上下文状态,即每个请求都是独立的:3.为每个资源设置URI:4.通过XML JS ...

  5. ArcMap如何修改地图坐标系统

    有时候,地图投影坐标需要作出修改,使得符合要求,不然空间参考不一样无法进行进一步的操作,分析等!下面介绍arcgis地图投影坐标的修改! 1.首先,将地图数据导入,这里我导入的是广西的边界图bound ...

  6. 修改Android系统关机动画

    文件路径:frameworks\base\services\core\java\com\android\server\power\ShutdownThread.java 在beginShutdownS ...

  7. 《ArcGIS Runtime SDK for Android开发笔记》——(7)、示例代码arcgis-runtime-samples-android的使用

    1.前言 学习ArcGIS Runtime SDK开发,其实最推荐的学习方式是直接看官方的教程.示例代码和帮助文档,因为官方的示例一般来说都是目前技术最新,也是最详尽的.对于ArcGIS Runtim ...

  8. 当你的域名是数字开头时如何命名java包路径

    例如:域名是1001y.net 理想的包路径是net.1001y,但由于java命名规范的问题,首字母不能为数字,这时我们只有两种选择: 1,net.$1001y 使用$符号作为首字母. 2,net. ...

  9. php的yii框架开发总结3

    利用yii里面的gii工具可以很容易的自动创建数据表相应的的CURD操作的基于MVC的文件: 首先,打开:自己网站/protected/config/main.php文件 'modules'=> ...

  10. python3绘图示例3(基于matplotlib:折线图等)

    #!/usr/bin/env python# -*- coding:utf-8 -*-from pylab import *from numpy import *import numpy # 数据点图 ...