hdu 3547 (polya定理 + 小高精)
DIY Cube
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 207 Accepted Submission(s): 111
Problem Description
Mr. D is interesting in combinatorial enumeration. Now he want to find out the number of ways on painting the vertexes of a cube. Suppose there are C different colors and two paintings are considered the same if they can transform from one to another by rotation.
Input
There are multiple test cases in the input, the first line of input contains an integer denoting the number of test cases.
For each test case, there are only one integer C, denoting the number of colors. (1 <= C <= 1000000000)
Output
For each test case, output the the number of painting ways. And if the number is equal or larger than 1015, output the last 15 digits.
Sample Input
3 1 2 112
Sample Output
Case 1: 1 Case 2: 23 Case 3: 031651434916928
Author
HyperHexagon
Source
HyperHexagon's Summer Gift (Original tasks)
Recommend
zhengfeng
polya定理的应用,需要加高精最后输出。如果想不到,你可以用置换群乘法让计算机代替你去算每种操作的循环节,我这里是已经在纸上算好的了。
假设有x种颜色。
对于一个cube有四种大置换:
1:固定对立的面旋转,共有3对对立面:
可得旋转90°与旋转270°互为逆操作,都有两个循环节,共有 3*2*x^2个不动点;
旋转180°有四个循环节,共有3*1*x^4个不动点;
共有3*2+3*1=9种置换。
2:固定对立的边旋转,共有6对对立边:
只可旋转180°,有四个循环节,共有6*1*x^4个不动点;
共有6种置换。
3:固定对立的角旋转,共有4对对立的角:
旋转120°与旋转270°互为逆操作,都有四个循环节,共有4*2*x^4 个不动点。
共4*2=8种置换。
4:不动:
有8个循环节,有X^8个不动点。
共1种置换。
所以共有24种置换。
共有x^8+17*x^4+6*x^2个不动点。
由L=1/|G| *Σ(D(ai))得:
等价类L=1/24*(x^8+17*x^4+6*x^2);
由于保留后15位,数字也过大,用大数与小数的高精度去处理。
下面给出代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#define clr(x) memset(x,0,sizeof(x))
#define cop(x,y) memcpy(x,y,sizeof(y))
#define LL long long
#define lim 10
using namespace std;
LL ans[];
LL xpow[];//x的幂
LL dv[];//x^(i/2)的系数
int dd[]={,,,,};
void add(LL *a,LL *b);//高精加
void mul(LL *a,int b);//高精乘
void div(LL *a,int b);//高精除
int main()
{
int T,x;
scanf("%d",&T);
for(int t=;t<=T;t++)
{
scanf("%d",&x);
printf("Case %d: ",t);
clr(ans);
clr(xpow);
xpow[]=;
for(int i=;i<=;i++)
{
mul(xpow,x);
if(i%==)
{
cop(dv,xpow);
mul(dv,dd[i/]);
add(ans,dv);
}
}
div(ans,);
int v=;
while(ans[v]== && v>=)
v--;
if(v>) v=;
for(int i=v;i>=;i--)
printf("%d",ans[i]);
printf("\n");
}
return ;
}
void mul(LL *a,int b)
{
LL ret=;
int v=;
while(a[v]== && v>=)
v--;
for(int i=;i<=v || ret!=;i++)
{
ret=ret/lim+a[i]*(LL)b;
a[i]=ret%lim;
}
return ;
}
void add(LL *a,LL *b)
{
LL ret=;
int v=;
while(a[v]== && b[v]== && v>=)
v--;
for(int i=;i<=v || ret!=;i++)
{
ret=ret/lim+a[i]+b[i];
a[i]=ret%lim;
}
return ; }
void div(LL *a,int b)
{
LL ret=;
int v=;
while(a[v]== && v>=)
v--;
for(int i=v;i>=;i--)
{
ret=ret*lim+a[i];
a[i]=ret/(LL)b;
ret%=(LL)b;
}
return ;
}
hdu 3547 (polya定理 + 小高精)的更多相关文章
- HDU 4633 Who's Aunt Zhang (Polya定理+快速幂)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4633 典型的Polya定理: 思路:根据Burnside引理,等价类个数等于所有的置换群中的不动点的个 ...
- hdu 1817 Necklace of Beads(Polya定理)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 3923 Invoker(polya定理+逆元)
Invoker Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 122768/62768 K (Java/Others)Total Su ...
- HDU 3923 Invoker 【裸Polya 定理】
参考了http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 的模板 对于每一种染色,都有一个等价群,例如旋转, ...
- polya定理小结
polya的精髓就在与对循环节的寻找,其中常遇到的问题就是项链染色类问题. 当项链旋转时有n种置换,循环节的个数分别是gcd(n, i); 当项链翻转时有n种置换,其中当项链珠子数位奇数时,循环节的个 ...
- 【转】Polya定理
转自:http://endlesscount.blog.163.com/blog/static/82119787201221324524202/ Polya定理 首先记Sn为有前n个正整数组成的集合, ...
- 【群论】polya定理
对Polya定理的个人认识 我们先来看一道经典题目: He's Circles(SGU 294) 有一个长度为N的环,上面写着“X”和“E”,问本质不同的环有多少个(不 ...
- [wikioi2926][AHOI2002]黑白瓷砖(Polya定理)
小可可在课余的时候受美术老师的委派从事一项漆绘瓷砖的任务.首先把n(n+1)/2块正六边形瓷砖拼成三角形的形状,右图给出了n=3时拼成的“瓷砖三角形”.然后把每一块瓷砖漆成纯白色或者纯黑色,而且每块瓷 ...
- Polya定理
http://www.cnblogs.com/wenruo/p/5304698.html 先看 Polya定理,Burnside引理回忆一下基础知识.总结的很棒. 一个置换就是集合到自身的一个双射,置 ...
随机推荐
- .NET FrameWork 中的 CTS
CTS:Common Type System 通用类型系统. 1.不仅可以把C#编译成.Net IL,还支持Basic.Python.Ruby等语言,甚至还支持Java.不同语言中的数据类型定义是不一 ...
- 联系博主 Contact
李莫 / Ray OI 蒟蒻一只 / A Player of Olympiad in Informatics QQ:740929894 邮箱 / Email :rayking2017@outlook. ...
- python初步学习-查看文档及数据类型转换
学会查看文档 python最权威的文档就是官方文档,因此,我们要学会查看官方文档.而在python解释器中,help() 命令就可以很权威的查看官方文档. 因此,我们要学会使用 help() 命令. ...
- solaris如何启动ssh服务
先查看一下ssh服务状态:# svcs或# svcs | grep sshonline Aug_07 svc:/network/ssh:default 如需要关闭ssh服务(关闭完可以 svcs | ...
- 一个基于时间注入的perl小脚本
use strict; use warnings; use LWP::Simple; my %table_and_leng; ;;$count++){ #print "Test Table: ...
- linux安装lamp
github https://github.com/zblogcn/zblogphp Installation If your server system: CentOS yum -y install ...
- 10.异步SRAM的FPGA读写操作
异步SRAM:正如其名,不是与特定的时钟信号同步运行,而是根据输入信号的状态运行的.因为没有信号表明读取时已确定了有效数据,也没有信号表明写入时已接收到数据,所以,需要获取制造商的数据手册,根据时序图 ...
- 从LFS官方文档构建完整Linux系统
从LFS官方文档构建完整Linux系统 http://www.cnblogs.com/sonofdark/p/4962609.html 这不是新手教程!!! Parallels Desktop (为防 ...
- CF625D Finals in arithmetic-构造,贪心,细节
题目链接:http://codeforces.com/contest/625/problem/D 题意: 给你一个数字字符串s,长度1e6,算是一个大数吧,让你找到一个x,使得,x加上 逆转(x)= ...
- web优化的方法
缓存(减小对服务器.数据库的压力) 生成静态页面(区别于缓存,数据量太大用“缓存”不利) URL重写(SEO,搜索引擎的优化) ajax的优化(SEO) <meta content=“” nam ...