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. Myeclipse报错-Java compiler level does not match 完美解决方法

    从别的地方导入一个项目的时候,经常会遇到eclipse/Myeclipse报Description  Resource Path Location Type Java compiler level d ...

  2. pprof 查看goroutine

    package main import ( "net/http" "runtime/pprof" ) var quit chan struct{} = make ...

  3. How to find your web part

         When we deploy a web part, we can find it on any pages through the follow steps:      Firstly, ...

  4. 剖析DI

    0x00.前言 当我们研究一些晦涩的源码,上网查阅资料的时候,映入眼帘的总有这么些名词:DIP.IOC.DI.DL.IOC容器这些专业名词.如果不懂这些名词背后的含义,我们内心有可能是这样的: 0x0 ...

  5. jmeter插件之VariablesFromCSV

    项目需求: 由于该项目的特殊性,需要新建很多个jmx脚本,并且这些jmx的全局用户变量都一样,如果要修改的话,没法做到统一修改. 实现思路: 为了满足需求,在jemter官网找到该插件Variable ...

  6. Python 3基础教程29-os模块

    本文介绍os模块,主要是介绍一些文件的相关操作. 你还有其他方法去查看os 1. help() 然后输入os 2. Python接口文档,前面提到的用浏览器打开的,os文件路径为:C:\Users\A ...

  7. 在阿里云上遇见更好的Oracle(一)

    2003年毕业那年正好遇上非典,好不容易找到一份制造工厂的工作,凭着一点点的SQL基础进入了IT部门,在那里第一次听说了Oracle.在此之前,我对数据库的认知基本还停留在Access阶段,耳闻过一点 ...

  8. 小旭讲解 LeetCode 53. Maximum Subarray 动态规划 分治策略

    原题 Given an integer array nums, find the contiguous subarray (containing at least one number) which ...

  9. Tensorflow Serving介绍及部署安装

    TensorFlow Serving 是一个用于机器学习模型 serving 的高性能开源库.它可以将训练好的机器学习模型部署到线上,使用 gRPC 作为接口接受外部调用.更加让人眼前一亮的是,它支持 ...

  10. c# 复选下拉框

    引用dll: http://pan.baidu.com/s/1qXa97UO 自定义类: namespace TMI_S { /// <summary> /// 功能描述:自定义多选下拉框 ...