poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286
题意:有红、绿、蓝三种颜色的n个珠子。要把它们构成一个项链,问有多少种不同的方法。旋转和翻转后同样的属于同一种方法。
polya计数。
搜了一篇论文Pólya原理及其应用看了看polya究竟是什么东东。它主要计算所有互异的组合的个数。对置换群还是似懂略懂。用polya定理解决这个问题的关键是找出置换群的个数及哪些置换群,每种置换的循环节数。像这样的不同颜色的珠子构成项链的问题能够把N个珠子看成正N边形。
Polya定理:(1)设G是p个对象的一个置换群。用k种颜色给这p个对象,若一种染色方案在群G的作用下变为还有一种方案,则这两个方案当作是同一种方案,这种不同染色方案数为:
。
(2) 对于N个珠子的项链,共同拥有n种旋转置换和n种翻转置换。
对于旋转置换:每种置换的循环节数c(fi) = gcd(n,i)。(i为一次转过多少个珠子)
对于翻转置换:假设n为奇数。共同拥有n种翻转置换。每种置换的循环节数c(f) = n/2 + 1;
假设n为偶数,c(f) = n/2的置换有n/2个; c(f) = n/2 + 1的置换有n/2个。
直接带入公式就KO了。
poj 1286
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <string.h>
#include <queue>
#include <string>
#include <stdlib.h>
#define LL long long
#define _LL __int64
#define eps 1e-8 using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 10; int n;
_LL ans; int gcd(int a, int b)
{
if(b == 0)
return a;
return gcd(b,a%b);
} int main()
{
while(~scanf("%d",&n))
{
if(n == -1)
break;
if(n == 0) //不考虑n=0的情况,会导致RE
{
printf("0\n");
continue;
}
ans = 0;
// n 种旋转置换 for(int i = 1; i <= n; i++)
ans += pow(3.0,gcd(n,i)); //m种翻转置换 if(n & 1)
{
ans += n * pow(3.0,n/2+1);
}
else
{
ans += n/2 * pow(3.0,n/2);
ans += n/2 * pow(3.0,n/2+1);
} ans = ans/2/n; printf("%I64d\n",ans);
}
return 0;
}
poj 2409
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <string.h>
#include <queue>
#include <string>
#include <stdlib.h>
#define LL long long
#define _LL __int64
#define eps 1e-8 using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 10; int c,s;
_LL ans; int gcd(int a, int b)
{
if(b == 0)
return a;
return gcd(b,a%b);
} int main()
{
while(~scanf("%d %d",&c,&s))
{
if(c == 0 && s == 0) break;
ans = 0; for(int i = 1; i <= s; i++)
ans += pow(c*1.0,gcd(s,i)); if(s & 1)
{
ans += s * pow(c*1.0,s/2+1);
}
else
{
ans += s/2 * pow(c*1.0,s/2);
ans += s/2 * pow(c*1.0,s/2+1);
}
ans = ans/2/s;
printf("%I64d\n",ans);
}
return 0;
}
poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)的更多相关文章
- poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>
链接:http://poj.org/problem?id=1286 http://poj.org/problem?id=2409 #include <cstdio> #include &l ...
- 数学计数原理(Pólya):POJ 1286 Necklace of Beads
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7763 Accepted: 3247 ...
- poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- POJ 1286 Necklace of Beads(项链的珠子)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7874 Accepted: 3290 ...
- POJ 1286 Necklace of Beads(Polya简单应用)
Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...
- POJ 2409 Let it Bead(Polya定理)
点我看题目 题意 :给你c种颜色的n个珠子,问你可以组成多少种形式. 思路 :polya定理的应用,与1286差不多一样,代码一改就可以交....POJ 1286题解 #include <std ...
- poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)
题目:http://poj.org/problem?id=2409 题意:用k种不同的颜色给长度为n的项链染色 网上大神的题解: 1.旋转置换:一个有n个旋转置换,依次为旋转0,1,2,```n-1. ...
- poj 1286 Necklace of Beads【polya定理+burnside引理】
和poj 2409差不多,就是k变成3了,详见 还有不一样的地方是记得特判n==0的情况不然会RE #include<iostream> #include<cstdio> us ...
- POJ 1286 Necklace of Beads(Polya原理)
Description Beads of red, blue or green colors are connected together into a circular necklace of n ...
随机推荐
- 匹配<a href="url">content</a>
grep -Po '<a href="(.*.rmvb")>(.*)</a>' te.txt | sed -n 's/<a href=\(.*\)&g ...
- SpringBoot读取配置properties配置文件
见:http://www.cnblogs.com/VergiLyn/p/6286507.html
- Node.js modules you should know about: request
Hey everyone! This is the fourth post in my new node.js modules you should know about article series ...
- Flex4+spring+hibernate+BlazeDS整合案例
http://wenku.baidu.com/link?url=7v5xAyD2nvChQRT60QewpvAASFHMZNvD0OxX11OASYvae8jbVNsr5I000TwwYOlChzq0 ...
- MySQL 5.5版本解决中文乱码问题时my.ini内[mysqld]项中不能再写default-character-set=utf8
来看看如何解决乱码问题: 在mysql中默认字符集是latin1, 想要设置字符集为uft-8,可以在 my.cnf 文件中添加以下设置: [client] default-character-set ...
- Oracle rac架构和原理
Oracle RAC Oracle Real Application Cluster (RAC,实时应用集群)用来在集群环境下实现多机共享数据库,以保证应用的高可用性:同时可以自动实现并行处理 ...
- apt-get无法下载,一些网址Not Found 404
apt-get无法下载,网址报 Not Found 404,原因是apt软件下载源有问题. 1.将/etc/apt/source.list里的内容替换. 在其他能够下载apt的ubuntu机器中拷贝过 ...
- Android之使用XMLPull解析xml(二)
转自:http://www.blogjava.net/sxyx2008/archive/2010/08/04/327885.html 介绍下在Android中极力推荐的xmlpull方式解析xml.x ...
- Android 项目的代码混淆,Android proguard 使用说明
简单介绍 Java代码是非常easy反编译的. 为了非常好的保护Java源码,我们往往会对编译好的class文件进行混淆处理. ProGuard是一个混淆代码的开源项目.它的主要作用就是混淆,当然它还 ...
- acd Convex(求面积)
Problem Description We have a special convex that all points have the same distance to origin point. ...