HDU 5868 Different Circle Permutation(burnside 引理)
HDU 5868 Different Circle Permutation(burnside 引理)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5868
Description
You may not know this but it's a fact that Xinghai Square is Asia's largest city square. It is located in Dalian and, of course, a landmark of the city. It's an ideal place for outing any time of the year. And now:
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.
Input
There are T tests (T≤50). Each test contains one integer N. 1≤N≤1000000000 (10^9). Process till the end of input.
Output
For each test, output the answer mod 1000000007 (10^9+7) in one line.
Sample Input
4
7
10
Sample Output
3
5
15
题意:
有n个人假设完全一样,其中有一部分人坐成一个圆,这些人中任意两个人之间的距离是2π/N的倍数,但是不是2π/N。如果有两种坐法,一种通过旋转可以变成另外一种坐法,我们就可以认为这是一种坐法,问总共有多少种坐法?
题解:
题解参照https://async.icpc-camp.org/d/546-2016 先膜一发菊苣。
首先是不考虑旋转同构的情况下,我们自己手动推几个就可以得到一个公式就是f(n)=f(n-1)+f(n-2)。这里我们注意一点,就是当n=1的时候我们当其为1 。(具体原因我也不清楚)。
然后就是我们使用 burnside 引理(对于一个置换f,若一个着色方案s经过置换后不变,称s为f的不动点。将f的不动点数目记为C(f),则可以证明等价类数目为所有C(f)的平均值。此结论称为 burnside 引理————来自训练指南)。
下面则是求不动点数目。对于这个我们则是依次计算旋转1,2,……n的不动点数目。前面我们定义了f(n)为不考虑旋转同构的状态。下面就是将循环数代入即可,其中循环节的个数为gcd(i,n)。
当然直枚举每个点必然会超时。我们可以使用 (∑f(d)*φ(n/d))/n 代替。其中d是n的因子。
代码:
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9+7 ;
struct matrix {
long long x1,x2 ;
long long x3,x4 ;
};
matrix mul(matrix a,matrix b){
matrix ans ;
ans.x1 = (a.x1*b.x1 + a.x2*b.x3)%mod ;
ans.x2 = (a.x1*b.x2 + a.x2*b.x4)%mod ;
ans.x3 = (a.x3*b.x1 + a.x4*b.x3)%mod ;
ans.x4 = (a.x3*b.x2 + a.x4*b.x4)%mod ;
return ans ;
}
long long quick_matrix(long long x){
x -= 4 ;
matrix ans,cal ;
ans.x1 = ans.x2 = ans.x3 = 1 ; ans.x4 = 0 ;
cal.x1 = cal.x2 = cal.x3 = 1 ; cal.x4 = 0 ;
while (x){
if (x%2)
ans = mul(ans,cal) ;
cal = mul(cal,cal) ;
x >>= 1 ;
}
return (ans.x1*4+ans.x2*3)%mod ;
}
long long fx(long long x){
if (x == 1)
return 1;
else if (x == 2)
return 3;
else if (x == 3)
return 4;
else return quick_matrix(x) ;
}
long long quick(long long a,long long n){
long long ans = 1 ;
long long cal = a ;
while (n){
if (n%2)
ans = (ans*cal)%mod ;
cal = (cal*cal)%mod;
n >>= 1;
}
return ans ;
}
long long euler(long long n)
{
long long ans = n;
long long 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;
}
long long solve(long long n){
if (n == 1)
return 2;
long long ans = 0;
long long nn = n ;
long long d;
long long i;
for (i = 1; i*i < n; i++){
if (n%i == 0){
ans = (ans + fx(i)*euler(nn/i) + fx(nn/i)*euler(i))%mod ;
}
}
if (i*i == n)
ans = (ans + fx(i)*euler(i))%mod ;
return (ans*quick(nn,mod-2))%mod;
}
int main()
{
long long n;
while (~scanf("%lld",&n))
printf("%lld\n",solve(n)) ;
return 0 ;
}
HDU 5868 Different Circle Permutation(burnside 引理)的更多相关文章
- HDU 5868 Different Circle Permutation Burnside引理+矩阵快速幂+逆元
题意:有N个座位,人可以选座位,但选的座位不能相邻,且旋转不同构的坐法有几种.如4个座位有3种做法.\( 1≤N≤1000000000 (10^9) \). 题解:首先考虑座位不相邻的选法问题,如果不 ...
- 解题:HDU 5868 Different Circle Permutation
题面 先往上套Burnside引理 既然要求没有$\frac{2*π}{n}$的角,也就是说两个人不能挨着,那么相当于给一个环黑白染色,两个相邻的点不能染白色,同时求方案数.考虑$n$个置换子群,即向 ...
- hdu 5868:Different Circle Permutation 【Polya计数】
似乎是比较基础的一道用到polya定理的题,为了这道题扣了半天组合数学和数论. 等价的题意:可以当成是给正n边形的顶点染色,旋转同构,两种颜色,假设是红蓝,相邻顶点不能同时为蓝. 大概思路:在不考虑旋 ...
- HDU 5868 Different Circle Permutation
公式,矩阵快速幂,欧拉函数,乘法逆元. $an{s_n} = \frac{1}{n}\sum\limits_{d|n} {\left[ {phi(\frac{n}{d})×\left( {fib(d ...
- hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理)
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K ...
- hdu 5868 Polya计数
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K ...
- 【等价的穿越】Burnside引理&Pólya计数法
Problem 起源: SGU 294 He's Circle 遗憾的是,被吃了. Poj有道类似的: Mission 一个长度为n(1≤n≤24)的环由0,1,2组成,求有多少本质不同的环. 实际上 ...
- [bzoj 1004][HNOI 2008]Cards(Burnside引理+DP)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1004 分析: 1.确定方向:肯定是组合数学问题,不是Polya就是Burnside,然后题目上 ...
- POJ 2888 Magic Bracelet(Burnside引理,矩阵优化)
Magic Bracelet Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 3731 Accepted: 1227 D ...
随机推荐
- NHibernate总结
NHibernate总结 现在的项目中数据访问使用的是NHibernate的一个ORM框架,小弟也是在后期加入项目组,之前对NHibernate就一直没有接触过,所以一直在学习NHibernate,都 ...
- hadoop集群环境的搭建
hadoop集群环境的搭建 今天终于把hadoop集群环境给搭建起来了,能够运行单词统计的示例程序了. 集群信息如下: 主机名 Hadoop角色 Hadoop jps命令结果 Hadoop用户 Had ...
- enode框架step by step之saga的思想与实现
enode框架step by step之saga的思想与实现 enode框架系列step by step文章系列索引: 分享一个基于DDD以及事件驱动架构(EDA)的应用开发框架enode enode ...
- 桥接模式及C++实现 C++设计模式-AbstractFactory抽象工厂模式
桥接模式及C++实现 桥接模式 先说说桥接模式的定义:将抽象化(Abstraction)与实现化(Implementation)分离,使得二者可以独立地变化. 桥接模式号称设计模式中最难理解的模式之一 ...
- 下载centos6.4
下载centos6.4 (原创)LAMP教程3-下载centos6.4 今天我要给大家讲的是安装CentOS-6.4-x86_64,是的没有错,就是64位的,因为我的机子是4G的内存,安装64位的ce ...
- STM8S ADC初始化设置及应用
//ADC通道号定义 #define ADC_Chanel0 (unsigned char)0x00 #define ADC_Chanel1 (unsigned char)0x01 #define A ...
- Citrix 服务器虚拟化之四 Xenserver资源池
Citrix 服务器虚拟化之四 Xenserver资源池 台主机,尽管这种限制没有执行.池总是至少有一个物理节点,称为主.只有主节点公开管理界面(使用XenCenter和XenServer命令行界面 ...
- 图的匹配问题与最大流问题(三)——最大流问题Ford-Fulkerson方法Java实现
上篇文章主要介绍了Ford-Fulkerson方法的理论基础,本篇给出一种Java的实现. 先借助伪代码熟悉下流程 FORD-FULKERSON(G,t,s) 1 for each edge(u,v) ...
- 从ICassFactory为CLSID为{17BCA6E8-A950-497E-B2F9-AF6AA475916F}的COM组件创建实例失败,原因是出现以下错误:c001f011.(Microsoft.Server.manageDTS
从ICassFactory为CLSID为{17BCA6E8-A950-497E-B2F9-AF6AA475916F}的COM组件创建实例失败,原因是出现以下错误:c001f011.(Microsoft ...
- 用浅/深拷贝、和HTML5方法解决js对象的引用的问题
先来看一个例子 例一: var a=[1,2,3]; var b=a; b.push(4); alert(b);//1,2,3,4 alert(a);//1,2,3,4 var a=[1,2,3]; ...
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5868
Description
You may not know this but it's a fact that Xinghai Square is Asia's largest city square. It is located in Dalian and, of course, a landmark of the city. It's an ideal place for outing any time of the year. And now:
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.
Input
There are T tests (T≤50). Each test contains one integer N. 1≤N≤1000000000 (10^9). Process till the end of input.
Output
For each test, output the answer mod 1000000007 (10^9+7) in one line.
Sample Input
4
7
10
Sample Output
3
5
15
题意:
有n个人假设完全一样,其中有一部分人坐成一个圆,这些人中任意两个人之间的距离是2π/N的倍数,但是不是2π/N。如果有两种坐法,一种通过旋转可以变成另外一种坐法,我们就可以认为这是一种坐法,问总共有多少种坐法?
题解:
题解参照https://async.icpc-camp.org/d/546-2016 先膜一发菊苣。
首先是不考虑旋转同构的情况下,我们自己手动推几个就可以得到一个公式就是f(n)=f(n-1)+f(n-2)。这里我们注意一点,就是当n=1的时候我们当其为1 。(具体原因我也不清楚)。
然后就是我们使用 burnside 引理(对于一个置换f,若一个着色方案s经过置换后不变,称s为f的不动点。将f的不动点数目记为C(f),则可以证明等价类数目为所有C(f)的平均值。此结论称为 burnside 引理————来自训练指南)。
下面则是求不动点数目。对于这个我们则是依次计算旋转1,2,……n的不动点数目。前面我们定义了f(n)为不考虑旋转同构的状态。下面就是将循环数代入即可,其中循环节的个数为gcd(i,n)。
当然直枚举每个点必然会超时。我们可以使用 (∑f(d)*φ(n/d))/n 代替。其中d是n的因子。
代码:
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9+7 ;
struct matrix {
long long x1,x2 ;
long long x3,x4 ;
};
matrix mul(matrix a,matrix b){
matrix ans ;
ans.x1 = (a.x1*b.x1 + a.x2*b.x3)%mod ;
ans.x2 = (a.x1*b.x2 + a.x2*b.x4)%mod ;
ans.x3 = (a.x3*b.x1 + a.x4*b.x3)%mod ;
ans.x4 = (a.x3*b.x2 + a.x4*b.x4)%mod ;
return ans ;
}
long long quick_matrix(long long x){
x -= 4 ;
matrix ans,cal ;
ans.x1 = ans.x2 = ans.x3 = 1 ; ans.x4 = 0 ;
cal.x1 = cal.x2 = cal.x3 = 1 ; cal.x4 = 0 ;
while (x){
if (x%2)
ans = mul(ans,cal) ;
cal = mul(cal,cal) ;
x >>= 1 ;
}
return (ans.x1*4+ans.x2*3)%mod ;
}
long long fx(long long x){
if (x == 1)
return 1;
else if (x == 2)
return 3;
else if (x == 3)
return 4;
else return quick_matrix(x) ;
}
long long quick(long long a,long long n){
long long ans = 1 ;
long long cal = a ;
while (n){
if (n%2)
ans = (ans*cal)%mod ;
cal = (cal*cal)%mod;
n >>= 1;
}
return ans ;
}
long long euler(long long n)
{
long long ans = n;
long long 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;
}
long long solve(long long n){
if (n == 1)
return 2;
long long ans = 0;
long long nn = n ;
long long d;
long long i;
for (i = 1; i*i < n; i++){
if (n%i == 0){
ans = (ans + fx(i)*euler(nn/i) + fx(nn/i)*euler(i))%mod ;
}
}
if (i*i == n)
ans = (ans + fx(i)*euler(i))%mod ;
return (ans*quick(nn,mod-2))%mod;
}
int main()
{
long long n;
while (~scanf("%lld",&n))
printf("%lld\n",solve(n)) ;
return 0 ;
}
题意:有N个座位,人可以选座位,但选的座位不能相邻,且旋转不同构的坐法有几种.如4个座位有3种做法.\( 1≤N≤1000000000 (10^9) \). 题解:首先考虑座位不相邻的选法问题,如果不 ...
题面 先往上套Burnside引理 既然要求没有$\frac{2*π}{n}$的角,也就是说两个人不能挨着,那么相当于给一个环黑白染色,两个相邻的点不能染白色,同时求方案数.考虑$n$个置换子群,即向 ...
似乎是比较基础的一道用到polya定理的题,为了这道题扣了半天组合数学和数论. 等价的题意:可以当成是给正n边形的顶点染色,旋转同构,两种颜色,假设是红蓝,相邻顶点不能同时为蓝. 大概思路:在不考虑旋 ...
公式,矩阵快速幂,欧拉函数,乘法逆元. $an{s_n} = \frac{1}{n}\sum\limits_{d|n} {\left[ {phi(\frac{n}{d})×\left( {fib(d ...
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K ...
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K ...
Problem 起源: SGU 294 He's Circle 遗憾的是,被吃了. Poj有道类似的: Mission 一个长度为n(1≤n≤24)的环由0,1,2组成,求有多少本质不同的环. 实际上 ...
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1004 分析: 1.确定方向:肯定是组合数学问题,不是Polya就是Burnside,然后题目上 ...
Magic Bracelet Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 3731 Accepted: 1227 D ...
NHibernate总结 现在的项目中数据访问使用的是NHibernate的一个ORM框架,小弟也是在后期加入项目组,之前对NHibernate就一直没有接触过,所以一直在学习NHibernate,都 ...
hadoop集群环境的搭建 今天终于把hadoop集群环境给搭建起来了,能够运行单词统计的示例程序了. 集群信息如下: 主机名 Hadoop角色 Hadoop jps命令结果 Hadoop用户 Had ...
enode框架step by step之saga的思想与实现 enode框架系列step by step文章系列索引: 分享一个基于DDD以及事件驱动架构(EDA)的应用开发框架enode enode ...
桥接模式及C++实现 桥接模式 先说说桥接模式的定义:将抽象化(Abstraction)与实现化(Implementation)分离,使得二者可以独立地变化. 桥接模式号称设计模式中最难理解的模式之一 ...
下载centos6.4 (原创)LAMP教程3-下载centos6.4 今天我要给大家讲的是安装CentOS-6.4-x86_64,是的没有错,就是64位的,因为我的机子是4G的内存,安装64位的ce ...
//ADC通道号定义 #define ADC_Chanel0 (unsigned char)0x00 #define ADC_Chanel1 (unsigned char)0x01 #define A ...
Citrix 服务器虚拟化之四 Xenserver资源池 台主机,尽管这种限制没有执行.池总是至少有一个物理节点,称为主.只有主节点公开管理界面(使用XenCenter和XenServer命令行界面 ...
上篇文章主要介绍了Ford-Fulkerson方法的理论基础,本篇给出一种Java的实现. 先借助伪代码熟悉下流程 FORD-FULKERSON(G,t,s) 1 for each edge(u,v) ...
从ICassFactory为CLSID为{17BCA6E8-A950-497E-B2F9-AF6AA475916F}的COM组件创建实例失败,原因是出现以下错误:c001f011.(Microsoft ...
先来看一个例子 例一: var a=[1,2,3]; var b=a; b.push(4); alert(b);//1,2,3,4 alert(a);//1,2,3,4 var a=[1,2,3]; ...