Polya定理

  L=1/|G|*(m^c(p1)+m^c(p2)+...+m^c(pk))

  G为置换群大小

  m为颜色数量

  c(pi)表示第i个置换的循环节数

  如置换(123)(45)(6)其循环节数为3

-------------------------------------------------------------------------------------------

 POJ1286&POJ2409

  都是简单的处理串珠子的问题。

  题目中隐藏着3种不同的置换类别。

  1.旋转

    注意不需要顺时针和逆时针分开考虑 因为顺时针旋转k位等同于逆时针旋转(n-k)位。

    另外当旋转了k位时的循环节数为gcd(k,n) 这个略加脑补也可得出。

  2.翻转(对称)

    需要分n的奇偶分开讨论

    当n为奇数时

      只有一种对称,即以每颗珠子与中心的连线所在的直线为对称轴。这个时候循环节数为(n+1)/2。

    当n为偶数时

      有两种对称,一种同奇数时的情况,但是此时相对的两颗珠子所成的直线为同一条

      所以循环节数为n/2+1,情况的数量也要减少一半。

      另一种是以两颗珠子连线的中点与中心连线所在的直线为对称轴。这种情况的循环节数为n/2,情况也是n/2种。

  这两道题的数据范围都很小,所以直接这样处理就可以了。

  

 

program poj1286;
var i,n:longint;
tot,sum:int64;
w:array[-..]of int64; function gcd(x,y:longint):longint;
begin
if y= then exit(x) else exit(gcd(y,x mod y));
end; begin
w[]:=;
for i:= to do w[i]:=w[i-]*;
readln(n);
while n<>- do
begin
if n= then
begin
writeln();
readln(n);
continue;
end;
tot:=;sum:=w[n];
for i:= to n- do
begin
inc(tot);
inc(sum,w[gcd(i,n)]);
end;
if odd(n) then
begin
inc(tot,n);
inc(sum,w[(n+) >> ]*n);
end else
begin
inc(tot,n >> );
inc(sum,w[n >> +]*n >> );
inc(tot,n >> );
inc(sum,w[n >> ]*n >> );
end;
writeln(sum div tot);
readln(n);
end;
end.
program poj2409;
var m,n,tot,sum:int64;
i:longint; function w(x:longint):int64;
var i:longint;
begin
w:=;
for i:= to x do w:=w*m;
end; function gcd(x,y:longint):longint;
begin
if y= then exit(x) else exit(gcd(y,x mod y));
end; begin
readln(m,n);
while (m<>)or(n<>) do
begin
tot:=;sum:=;
for i:= to n do
begin
inc(tot);
inc(sum,w(gcd(i,n)));
end;
if odd(n) then
begin
inc(tot,n);
inc(sum,w((n+) >> )*n);
end else
begin
inc(tot,n >> );
inc(sum,w(n >> )* n >> );
inc(tot,n >> );
inc(sum,w(n >> +)* n >> );
end;
writeln(sum div tot);
readln(m,n);
end;
end.

----------------------------------------------------------------------------------

POJ2154

  

  感觉非常坑啊...

  首先觉得这道题挺好的...数据范围非常大

  由于用到gcd的统计所以自然而然想到了欧拉函数

  然后套一下应该就出来了...

  但是为什么我做了这么久...

  有几个需要注意的地方

  1.最后除以|G|在这里也就是n的步骤由于在取模意义下所以会出错,但是很神奇的发现快速幂的底数也都是n(大概这也是题目中长度和颜色数相同的意图吧),只要将次数-1就可以了。

  2.直接这样会TLE,欧拉函数的求解还需要用欧拉线筛来优化。即用已有的质因子来求phi。过程很简单就不多提了。

  值得一提的是最后一次TLE到AC的跨越仅仅是因为一个变量的类型。即ans变量改成longint就可以过了。

  再一次印证了张老师几年前提到的”空间会影响时间“

  另外在这道题中,正巧将前几天学的欧拉函数和欧拉线筛都运用了起来,感觉非常不错。

program poj2154;
const maxn=trunc(sqrt());
var t,test,n,tt:longint;
vis:array[-..maxn]of boolean;
p:array[-..maxn]of longint; procedure build;
var i,j:longint;
begin
fillchar(vis,sizeof(vis),true);
p[]:=;
for i:= to maxn do
begin
if vis[i] then
begin
inc(p[]);p[p[]]:=i;
end;
for j:= to p[] do
begin
if i*p[j]>maxn then break;
vis[i*p[j]]:=false;
if i mod p[j]= then break;
end;
end;
end; function phi(x:longint):longint;
var i,ans,tem:longint;
begin
ans:=x;tem:=x;
for i:= to p[] do if tem>=p[i]*p[i] then
//刚开始写成了tem>=p[i]就失去了优化的意义TAT
begin
if x mod p[i]= then ans:=ans div p[i]*(p[i]-);
//在ans是longint的情况下先乘后除会爆
while x mod p[i]= do x:=x div p[i];
end else break;
if x<> then ans:=ans div x*(x-);
//这里也涉及到运算顺序的问题
exit(ans mod tt);
end; function mul(a,b:longint):longint;
var ans,w:int64;
begin
ans:=;w:=a mod tt;
while b<> do
begin
if b and = then ans:=(ans*w) mod tt;
w:=(w*w) mod tt;
b:=b >> ;
end;
exit(ans);
end; function solve:longint;
var i:longint;
ans:int64;
begin
ans:=;
for i:= to trunc(sqrt(n)) do if n mod i= then
begin
ans:=(ans+phi(n div i)*mul(n,i-)) mod tt;
if i*i<>n then ans:=(ans+phi(i)*mul(n,n div i-)) mod tt;
end;
exit(ans);
end; begin
readln(test);
build;
for t:= to test do
begin
readln(n,tt);
writeln(solve);
end;
end.

[POJ1286&POJ2154&POJ2409]Polya定理的更多相关文章

  1. POJ2154 Color(Polya定理)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11654   Accepted: 3756 Description Bead ...

  2. poj2154 Color ——Polya定理

    题目:http://poj.org/problem?id=2154 今天学了个高端的东西,Polya定理... 此题就是模板,然而还是写了好久好久... 具体看这个博客吧:https://blog.c ...

  3. poj2409(polya 定理模板)

    题目链接:http://poj.org/problem?id=2409 题意:输入 m, n 表示有 m 种颜色,要构造一个长度为 n 的手环,旋转和对称的只算一种,问能组成多少个不同的手环. 思路: ...

  4. 【poj2154】Color Polya定理+欧拉函数

    题目描述 $T$ 组询问,用 $n$ 种颜色去染 $n$ 个点的环,旋转后相同视为同构.求不同构的环的个数模 $p$ 的结果. $T\le 3500,n\le 10^9,p\le 30000$ . 题 ...

  5. 【poj2409】Let it Bead Polya定理

    题目描述 用 $c$ 种颜色去染 $r$ 个点的环,如果两个环在旋转或翻转后是相同的,则称这两个环是同构的.求不同构的环的个数. $r·c\le 32$ . 题解 Polya定理 Burnside引理 ...

  6. poj2409:Let it Bead(置换群 polya定理)

    题目大意:长度为n的项链,要染m种颜色,可以通过旋转或翻转到达的状态视为同一种,问有多少种染色方案. 学了一波polya定理,发现很好理解啊,其实就是burnside定理的扩展. burnside定理 ...

  7. 【数论】【Polya定理】poj1286 Necklace of Beads

    Polya定理:设G={π1,π2,π3........πn}是X={a1,a2,a3.......an}上一个置换群,用m中颜色对X中的元素进行涂色,那么不同的涂色方案数为:1/|G|*(mC(π1 ...

  8. POJ2409 Let it Bead(Polya定理)

    Let it Bead Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6443   Accepted: 4315 Descr ...

  9. POJ2154 Color 【Polya定理 + 欧拉函数】

    题目 Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). ...

随机推荐

  1. 揭秘css

    这是我看到非常好的一本电子教程,可以当参考手册使用,链接

  2. 【Linux运维】Centos7上借助ansible搭建LVS+Keepalived

    安装ansible 安装ansible: [root@localhost ~]# /etc/hosts 192.168.19.129 web129.yanglt.com web129 192.168. ...

  3. Cassandra - Insert after Delete fails silently

    在delete一条数据后,再insert 相同内容的数据,结果看起来是成功的,但是当你去查找这个数据,却没有任何内容,整个过程并且没有任何异常提示. 这往往发生在单元测试的时候,我们反复清理和写入数据 ...

  4. python基础之删除文件及删除目录的方法

    下面来看一下python里面是如何删除一个文件及文件夹的~~ 1 2 3 4 5 6 7 8 #首先引入OS模块 import os #删除文件:  os.remove() #删除空目录:  os.r ...

  5. Xcode 自动打包之旅【本文摘自智车芯官网】

    由于公司项目很多,作为iOS端的开发工程师,在打包和上传App Store过程中超级费时,而且往往会有频繁更改需求重新打包.上传的情况.这些过程让我不胜其烦.之前有听说过自动打包,一直没有时间尝试,此 ...

  6. 编程练习:寻找发帖"水王"扩展问题一

    回顾 寻找发帖水王的问题总结起来就是在一个数组中某一个元素出现次数超过了数组长度的一半,那么可以很顺利的找到这个元素,实现见"编程练习:寻找发帖水王" 扩展 上面的问题中,强调了某 ...

  7. 【Solr】——Solr7安装教程

    前提 solr已经升级7.1,但是我们公司的solr还是使用的4.4,你们说low不low!!!重要的是,人家花费了大气将solr升级,从技术的角度来说solr7比solr4那是翻天覆地的改变! so ...

  8. Java空指针异常解决方法

    Throwable是所有错误或异常的超类,只有当对象是这个类的实例时才能通过Java虚拟机或者Java throw语句抛出. 当Java运行环境发出异常时,会寻找处理该异常的catch块,找到对应的c ...

  9. Concurrent.util中的一些类

    package com.bjsxt.height.concurrent019; import java.io.IOException; import java.util.Random; import ...

  10. 批处理之SET命令

    除了 下面分别介绍: 表示第二个字符到倒数第三个字符的值