poj 1286 Necklace of Beads
这是做的第一道群论题,自然要很水又很裸。注意用long long。
就是用到了两个定理
burnside :不等价方案数=每个置换的不动置换方案数的和 / 置换个数
polya: 一个置换的不动置换方案数=k^(这个置换的循环个数)
先看第一个博客再看第二个
http://endlesscount.blog.163.com/blog/static/82119787201221324524202/
这两个蛮好的,上代码:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; int n; long long mi(int a)
{
long long ans = , zan = ;
while (a)
{
if (a & ) ans *= zan;
zan *= zan;
a >>= ;
}
return ans;
} int gcd(int a, int b)
{
if (!b) return a;
return gcd(b, a%b);
} int main()
{
scanf("%d", &n);
while (n != -)
{
if (n == )
{
printf("0\n");
scanf("%d", &n);
continue;
}
int Gcount = *n;
long long ans = ;
for (int i = ; i <= n; ++i)
ans += mi(gcd(i,n));
if (n % == ) ans += mi(n/)*n/ + mi(n/+)*n/;
else ans += mi(n/+)*n;
printf("%I64d\n", ans / Gcount);
scanf("%d", &n);
}
return ;
}
poj 1286 Necklace of Beads的更多相关文章
- 数学计数原理(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(项链的珠子)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7874 Accepted: 3290 ...
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- POJ 1286 Necklace of Beads(Polya简单应用)
Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学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 ...
- POJ 1286 Necklace of Beads(Polya原理)
Description Beads of red, blue or green colors are connected together into a circular necklace of n ...
- 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(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- poj 1286 Necklace of Beads【polya定理+burnside引理】
和poj 2409差不多,就是k变成3了,详见 还有不一样的地方是记得特判n==0的情况不然会RE #include<iostream> #include<cstdio> us ...
随机推荐
- MySQL锁系列1
http://www.cnblogs.com/xpchild/p/3782311.html MySQL的锁:MySQL内部有很多种类的锁,按照用途不同,可以分为两类:1. 保护内存结构的锁,实现同 ...
- 《C和指针》之ANSI C标准输入输出函数
一.I/O流操作一般流程: (1)为每一个要打开的文件定义一个FILE *类型的指针变量,这个指针变量将指向I/O流使用的FILE结构体. (2)使用fopen函数打开I/O流.要打开一个I/O流,必 ...
- SqlDependency缓存数据库表小案例
SqlDependency的简介: SqlDependency是outputcache网页缓存的一个参数,它的作用是指定缓存失效的数据库依赖项,可以具体到数据库和表. SqlDependency能解决 ...
- php版DES
class DES { var $key; var $iv; //偏移量 function DES( $key, $iv=0 ) { //key长度8例如:1234abcd $this->key ...
- Java_Hbase Timeout issue
设置参数hbase.rpc.timeout <property><name>hbase.regionserver.lease.period</name><va ...
- hive-安装MySQL(centos6.4)
为安装hive做准备,以前装过无数次,在线的.tar包的,一直不用忘得差不多了. centos6.4 虚拟机 先看有没有装,有的话应该是自带的,卸载就可以了 命令分别是 然后在线安装,命令是 (-y是 ...
- STL之heap
STL的堆操作 STL里面的堆操作一般用到的只有4个:make_heap();.pop_heap();.push_heap();.sort_heap(); 他们的头文件函数是#include < ...
- ng中用$http接后台接口的异步坑
最近笔者在一个项目中用ng去接后台的接口.因为前后端都是新手,前端的不懂后台,且没有经验:后端的不懂前端,也没有经验,然后接口bug百出,文档写得乱.一个接口,后台改了三次,我也是寸步难行. 首先来看 ...
- 无需WEB服务器的WEBServices
本文将介绍如何将Indy控件组与Delphi 6的Web Services (SOAP)支持相结合.关于如何创建Web Services的更多信息,请参阅Nick Hodges的文章,<Web上 ...
- 关于MapReduce单词统计的例子:
要统计的文件的文件名为hello hello中的内容如下 hello you hello me 通过MapReduce程序统计出文件中的各个单词出现了几次.(两个单词之间通过tab键进行的分割) im ...