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 ...
随机推荐
- Chrome DevTools Protocol Viewer
Chrome DevTools Protocol Viewer awesome-chrome-devtools
- cocos2d-x3.0 Slider
.h #include "cocos2d.h" #include "cocos-ext.h" #include "ui/CocosGUI.h" ...
- Android 手机 ADB FastBoot 命令基本用法
adb用法: 准备: 1.在电脑上安装相应的USB驱动,在各分区置顶帖子有下载链接 2.手机进入设置->开发人员选项->勾选USB调试 adb devices 查看是否有设备 adb sh ...
- %( $# > 1 %? if (tid() in trace) %) 是什么意思
http://blog.csdn.net/sunnybeike/article/details/7769663 http://blog.163.com/digoal@126/blog/static/1 ...
- java基础学习总结——static关键字
一.static关键字
- [Unity Editor]10行代码搞定Hierarchy排序
在日常的工作和研究中,当给我们的场景摆放过多的物件的时候,Hierarchy面板就会变得杂乱不堪.比如这样: 过多的层次结构充斥在里面,根层的物件毫无序列可言,整个层次面板显示非常的杂乱不堪,如 ...
- spring MVC 与 struts 的区别
当初选框架的时候目的比较单纯---springmvc支持rest,小生对restful url由衷的喜欢 不用不知道一用就发现开发效率确实比struts2高 我们用struts2时采用的传统的配置文件 ...
- Java 复制大文件方式(nio2 FileChannel 拷贝文件能力测试)
目前为止,我们已经学习了很多 Java 拷贝文件的方式,除了 FileChannel 提供的方法外,还包括使用 Files.copy() 或使用字节数组的缓冲/非缓冲流.那个才是最好的选择呢?这个问题 ...
- 图片碎片化mask动画
图片碎片化mask动画 效果 源码 https://github.com/YouXianMing/Animations // // TransformFadeViewController.m // A ...
- Struts2 校验框架学习笔记
Struts2 校验框架 Struts2 和Struts1同样也提供了校验框架,但在Struts2 已经不再把校验框架做为一个插件,而是已经内置到了Struts2中,而且配置起来更为简单方便,功能也更 ...