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 ...
随机推荐
- MVC之Global.asax解析
大家看到上面的代码了,Application_Start大家都知道这是应用程序启动入口. AreaRegistration.RegisterAllAreas是什么呢? 我们先看看微软官方的注解: 我们 ...
- 学习JavaEE,对比ASP.NET顿悟出一点点道理
图一 图二 配套说明: 步骤一.客户端向web服务器(tomcat)发送http请求 步骤二.tomcat接收到请求后,将请求信息交给servlet容器,由servlet容器对请求进行封装(HttpS ...
- no device found for connection ‘ System eth0′
解决办法: 1.删除/etc/udev/rules.d/70-persistent-net.rules文件,重启系统. 2.如果上面的不起作用,那么去看ifcfg-eth0文件中的HWADDR是否正确 ...
- 由最小生成树(MST)到并查集(UF)
背景 最小生成树(Minimum Spanning Tree)的算法中,克鲁斯卡尔算法(Kruskal's algorithm)是一种常用算法. 在克鲁斯卡尔算法中的一个关键问题是如何判断图中的两个点 ...
- Shell脚本里的双冒号是什么意思
这个是代码开发风格,其实也就是一个函数名,相当于下划线分割,但改读成包名之后就意义不一样.这个是根据Google的Shell开发规范进行定义的. 参考: https://google.github.i ...
- 使用Chrome快速实现数据的抓取(三)——JQuery
使用Chrome抓取页面一个非常方便的地方就是它可以执行JS,也就是说我们可以通过JS函数获取我们想要的数据.一个非常强大易用的库就是Jquery,本文就简单的介绍一下使用Chrome获取数据时Jqu ...
- WordPress 客户端软件列表
Windows: BlogDesk BlogJet Blog Writer Chrysanth WebStory Deepest Sender (Firefox或SeaMonkey扩展,跨平台- De ...
- 01使用ILDasm.exe将可执行文件反编译成IL代码
控制台代码 using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args ...
- Excel向上取整
CEILING函数语法:CEILING(number,significance)
- 【BestCoder】【Round#41】
枚举+组合数?+DP+数学问题 http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=582 QAQ许久没打过比赛,来一发BC,结果还是只 ...