hdu 5868 Polya计数
Different Circle Permutation
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 218 Accepted Submission(s): 106
There are N children from a nearby primary school flying kites with a teacher. When they have a rest at noon, part of them (maybe none) sit around the circle flower beds. The angle between any two of them relative to the center of the circle is always a multiple of 2πN but always not 2πN.
Now, the teacher raises a question: How many different ways there are to arrange students sitting around the flower beds according to the rule stated above. To simplify the problem, every student is seen as the same. And to make the answer looks not so great, the teacher adds another specification: two ways are considered the same if they coincide after rotating.
7
10
5
15
/*
hdu 5868 Polya计数 problem:
给你n个人,围绕成圆坐下,任意两人之间的距离必需是2pi/n的倍数.求旋转等效的情况下有多少种方案数 solve:
相当于给你n个间距为2pi/n的点,然后进行黑白染色,黑点不能相邻. (黑点表示坐人)
考虑Polya计数的话,需要枚举长度且得到长度为i的方案数.
找规律可以发现 f[n] = f[n-1] + f[n-2],用矩阵快速幂可以快速求出 hhh-2016-09-20 19:26:01
*/
#pragma comment(linker,"/STACK:124000000,124000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#define lson i<<1
#define rson i<<1|1
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define key_val ch[ch[root][1]][0]
using namespace std;
const int maxn = 200100;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
struct Matrix
{
ll ma[2][2];
Matrix()
{
memset(ma,0,sizeof(ma));
}
}; Matrix mat;
Matrix from; Matrix Mul(Matrix a,Matrix b)
{
Matrix c;
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 2; j++)
{
c.ma[i][j] = 0;
for(int k = 0; k < 2; k++)
{
c.ma[i][j] = c.ma[i][j] + a.ma[i][k]*b.ma[k][j] % mod;
c.ma[i][j] %= mod;
}
}
}
return c;
} Matrix Pow(int n)
{
Matrix cnt;
Matrix t = mat;
memset(cnt.ma,0,sizeof(cnt.ma));
for(int i = 0; i < 2; i++)
cnt.ma[i][i] = 1;
while(n)
{
if(n & 1)
cnt = Mul(cnt,t);
t = Mul(t,t);
n >>= 1;
}
return cnt;
} void init()
{
mat.ma[0][0] = 1,mat.ma[0][1] = 1,mat.ma[1][0] = 1,mat.ma[1][1] = 0;
from.ma[0][0] = 3,from.ma[1][0] = 1,from.ma[0][1] = 0,from.ma[1][1] = 0;
}
int n;
ll f(int i)
{
if(i == 1)
return 1;
if(i == 2)
return 3;
Matrix t = Mul(Pow(i-2),from);
return t.ma[0][0];
} ll pow_mod(ll a,ll n)
{
ll ret = 1;
a %= mod;
while(n)
{
if(n & 1) ret = ret*a%mod;
a = a*a%mod;
n >>= 1;
}
return ret%mod;
} ll euler(ll n)
{
ll ans = n;
ll i;
for (i = 2; i*i <= n; i++)
{
if (n%i == 0)
{
while (n%i == 0)
n /= i;
ans = ans/i*(i-1) ;
}
}
if (n != 1)
ans = ans/n*(n-1);
return ans;
} void cal(int n)
{
if(n == 1)
{
printf("2\n");
return ;
}
ll ans = 0;
for(int i = 1; i*i <= n; i++)
{
if(n % i == 0)
{
ans = (ans + f(i)*euler(n/i)%mod)%mod;
if( i*i != n)
{
ans = (ans + f(n/i)*euler(i)%mod)%mod;
}
}
}
// cout <<ans <<endl;
ans = ans*pow_mod(n,mod-2)%mod;
printf("%I64d\n",ans);
} int main()
{
init();
// for(int i =1 ;i <= 10;i++)
// cout << f(i) <<endl;
// for(int i =1 ;i <= 10;i++)
// cout << euler(i) <<endl;
while(scanf("%d",&n) != EOF)
{
init();
cal(n);
}
}
hdu 5868 Polya计数的更多相关文章
- hdu 2865 Polya计数+(矩阵 or 找规律 求C)
Birthday Toy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 2239 polya计数 欧拉函数
这题模数是9937还不是素数,求逆元还得手动求. 项链翻转一样的算一种相当于就是一种类型的置换,那么在n长度内,对于每个i其循环节数为(i,n),但是由于n<=2^32,肯定不能直接枚举,所有考 ...
- hdu 5868:Different Circle Permutation 【Polya计数】
似乎是比较基础的一道用到polya定理的题,为了这道题扣了半天组合数学和数论. 等价的题意:可以当成是给正n边形的顶点染色,旋转同构,两种颜色,假设是红蓝,相邻顶点不能同时为蓝. 大概思路:在不考虑旋 ...
- HDU 4633 Who's Aunt Zhang (2013多校4 1002 polya计数)
Who's Aunt Zhang Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 《程序设计中的组合数学》——polya计数
我们在高中的组合数学中常常会碰到有关涂色的问题,例如:用红蓝两种颜色给正方形的四个顶点涂色,会有几种不同的方案.在当时,我们下意识的认为,正方形的四个顶点是各不相同的,即正方形是固定的.而实际上我们知 ...
- Polya计数
Let it Bead Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5365 Accepted: 3585 Descr ...
- HDU 5868 Different Circle Permutation(burnside 引理)
HDU 5868 Different Circle Permutation(burnside 引理) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=586 ...
- 组合数学及其应用——polya计数
在处理类似下面的问题中,一般的计数方法会出现问题:假如你要用红.蓝两种颜色给一个正四面体的四个顶点着色,试问存在多少种不同的着色方案? 在高中我们常用的方法是模拟涂色过程,分情况讨论,然后基于分步乘法 ...
- 群论&Polya计数
群论&Polya计数 其实在我听课的过程中,我发现针对于学习OI中的群并没有什么过多必要向内学习... 群 以后会补的. 就是\(QQ\)群. 置换 置换就是一个... \[ \begin{m ...
随机推荐
- Beta阶段敏捷冲刺每日报告——Day0
下一阶段需要改进完善的功能: 搜索框在Firefox和IE中显示不正常问题 下一阶段新增的功能: ToDoList功能:针对博主的功能,在博主登录之后可以添加和修改待办事项,每个事项包括标题.内容.日 ...
- beta版本复审
C++team复审 小组 优点 缺点 打分 MyGod小组 MyGod团队开发了一个让武汉大学的学生能够方便地了解校内二手物品交易信息,并进行相应的交易的安卓app.出发点不错,有创新点.使用了一下他 ...
- Python web服务器
Python 配置wsgi接口# 引入Python wsgi包 from wsgiref.simple_server import make_server # 撰写服务器端程序代码 def Appli ...
- VS系列控制台闪退解决
查阅--->总结-->实践--> 按红色标识走 ,完美解决! 至此,完美解决:原理不深究:
- Spring Cache扩展:注解失效时间+主动刷新缓存(二)
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- 说说Java代理模式
代理实现可以分为静态代理和动态代理. 静态代理 静态代理模式其实很常见,比如买火车票这件小事:黄牛相当于是火车站的代理,我们可以通过黄牛买票,但只能去火车站进行改签和退票.在代码实现中相当于为一个委托 ...
- copy代码(含static对象)留下的致命错误
本来以为这个bug快改不好了,然而发现了问题所在 copy代码没有完全改掉对象名称,导致对象重复创建了,由于是static所以debug过程中 注释了addProperty(gridRowDetail ...
- Apache命令
参考于:http://www.jinbuguo.com/apache/menu22/programs/apxs.html 安装httpd-devel才有apxs
- linux环境安装mysql,以及mysql基本的终端操作命令
linux环境下安装mysql服务器.客户端mysql简单的终端操作指令(使用数据库.简单的增删改查和备份恢复)1 SQL: Structured Query Language 结构化查询语言. 运用 ...
- Windows10+Docker搭建分布式Redis集群(一)
摘要,Docker for Windows 仅支持专业版 目录 第一步:检查系统支持虚拟化 第二步:下载Docker对应版本 第三步:配置镜像加速 第一步:检查系统是否支持虚拟化 Docker前提是需 ...