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 ...
随机推荐
- ZJU-PAT 1065. A+B and C (64bit) (20)
Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C. Input S ...
- javaio学习笔记-字符流类(1)
1.java.io包中的字符流类-BufferedReader和BufferedWriter: BufferedReader:缓存的输入字符流; BufferedWriter:缓存的输出字符流; In ...
- Fedora 下 安装 chrome
一.下载安装包,安装 1.去google 下载安装包 2.终端下 运行命令: rpm -ivh google-chrome-stable_current_i386.rpm 3. 出现如下 ...
- NonEmpty和Non Empty的区别[转]
One of my favourite questions in MDX is the difference between Non Empty and NonEmpty because even t ...
- php上传常见文件类型对应的$_FILES["file"]["type"](转)
php上传常见文件类型对应的$_FILES["file"]["type"] from:http://hi.baidu.com/7book/item/374971 ...
- java_io_操作封装
package com.wiker; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import j ...
- BootStrap2学习日记6---代码
<:表示“<” >:表示“>” 在BootStrap中标记代码的标签使用<code>,标记代码块使用<pre>(里面的代码特殊标签必须转义) ...
- The Romantic Hero
Problem Description There is an old country and the king fell in love with a devil. The devil always ...
- JavaFX(二)自定义窗口标题栏
1.问题场景 PC客户端登录界面仿QQ,上边显示图片,下边显示输入框和登录按钮.而JavaFX默认的窗口,不满足需求. 2.解决思路 隐藏窗口默认的标题栏,使用创建label对象,使用css将按钮图片 ...
- 自定义 Yasnippet 模板
yasnippet可以把我们常用的代码段或文本储存起来,到使用的时候只需键入几个字母就会自动带出. 比如我们在写python代码时,常常会在文件的第一行写下: #!/usr/bin/env pytho ...