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. Mac下安装pear库+phpDocumentor

    1. 首先安装pear: curl -o go-pear.php https://pear.php.net/go-pear.phar 看见这个就安装OK: % Total % Received % X ...

  2. 剑指offer-二进制中1的个数11

    题目描述 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. class Solution: def NumberOf1(self, n): # write code here coun ...

  3. [Binary Search] Leetcode 35, 74

    35. Search Insert Position Description Given a sorted array and a target value, return the index if ...

  4. windows基础知识(win7)

    右击 显示: 对设备进行管理: 在计算机属性中,开远程连接 控制面板: 控制面板下的操作中心: 控制面板下的管理工具: 控制面板下的默认程序: 控制面板下的日期时间: 控制面板下的鼠标: 控制面板下的 ...

  5. 数论初步——Eratosthenes筛法

    具体内容见紫书p312-p313 一.用Eratosthenes筛法构造1~n的素数表 思想:对于不超过n的每个非负整数p,删除2p,3p,4p…,当处理完所有的数后,还没有被删除的就是素数. 代码: ...

  6. eclipse安装问题

    eclipse安装之前需要安装JDK. 注意:eclipse和JDK需要一致,如都是64位或者都是32位. 不然会报错.

  7. Delphi函数详解:全局函数,内部函数,类的成员函数,类的静态方法

    1. Delphi中的全局函数 //要点: 需要给其他单元调用, 必须在 interface 声明, 但必须在 uses 区后面 unit Unit1; interface uses   Window ...

  8. OJ 列表

    维护一个 OJ 列表.(这件事似乎没啥意义?) AtCoder hihoCoder Codeforces DMOJ CodeChef CS Academy HackerRank HackerEarth ...

  9. [洛谷P2763]试题库问题

    题目大意:有 $k$ 种类型和 $n$ 个题目,每个题目会适应部分类型,第$i$个类型需要$s_i$的题,一道题只能满足一种类型,现要求出满足所有类型的题目的方案 题解:看到匹配,想到网络流,源点向试 ...

  10. MySQL in查询优化

    https://blog.csdn.net/gua___gua/article/details/47401621 MySQL in查询优化<一> 原创 2015年08月10日 17:57: ...