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定理 + 小高精)的更多相关文章

  1. HDU 4633 Who's Aunt Zhang (Polya定理+快速幂)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4633 典型的Polya定理: 思路:根据Burnside引理,等价类个数等于所有的置换群中的不动点的个 ...

  2. hdu 1817 Necklace of Beads(Polya定理)

    Necklace of Beads Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. HDU 3923 Invoker(polya定理+逆元)

    Invoker Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 122768/62768 K (Java/Others)Total Su ...

  4. HDU 3923 Invoker 【裸Polya 定理】

    参考了http://blog.csdn.net/ACM_cxlove?viewmode=contents           by---cxlove 的模板 对于每一种染色,都有一个等价群,例如旋转, ...

  5. polya定理小结

    polya的精髓就在与对循环节的寻找,其中常遇到的问题就是项链染色类问题. 当项链旋转时有n种置换,循环节的个数分别是gcd(n, i); 当项链翻转时有n种置换,其中当项链珠子数位奇数时,循环节的个 ...

  6. 【转】Polya定理

    转自:http://endlesscount.blog.163.com/blog/static/82119787201221324524202/ Polya定理 首先记Sn为有前n个正整数组成的集合, ...

  7. 【群论】polya定理

    对Polya定理的个人认识     我们先来看一道经典题目:     He's Circles(SGU 294)         有一个长度为N的环,上面写着“X”和“E”,问本质不同的环有多少个(不 ...

  8. [wikioi2926][AHOI2002]黑白瓷砖(Polya定理)

    小可可在课余的时候受美术老师的委派从事一项漆绘瓷砖的任务.首先把n(n+1)/2块正六边形瓷砖拼成三角形的形状,右图给出了n=3时拼成的“瓷砖三角形”.然后把每一块瓷砖漆成纯白色或者纯黑色,而且每块瓷 ...

  9. Polya定理

    http://www.cnblogs.com/wenruo/p/5304698.html 先看 Polya定理,Burnside引理回忆一下基础知识.总结的很棒. 一个置换就是集合到自身的一个双射,置 ...

随机推荐

  1. 25、如何实现redis集群?

    由于Redis出众的性能,其在众多的移动互联网企业中得到广泛的应用.Redis在3.0版本前只支持单实例模式,虽然现在的服务器内存可以到100GB.200GB的规模,但是单实例模式限制了Redis没法 ...

  2. ASP.NET AjaxControlToolkit-Framework4.0 配置实用(简单介绍CalendarExtender日期控件)

    1:下载:AjaxControlToolkit Ajax Control Toolkit .NET 4 Ajax Control Toolkit .NET 4.5 Ajax Control Toolk ...

  3. 关于RecylerView:1.在ScrollView的RecylerView滑动事件的处理。2.item之间的距离 小数取整

    1.在ScrollView的RecylerView滑动事件的处理. 在布局文件中在RecylerView外包裹一层相对布局 2.RecylerView item之间的距离 (1)编写SpaceItem ...

  4. jQuery Validate插件 验证实例

    官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation Validate手册: http://www.cnblogs.co ...

  5. appium===使用weditor代替ui automator viewer

    weditor 一个元素定位工具,并可实现通过wifi连接移动端进行定位. https://github.com/openatx/uiautomator2 python安装方式: pip instal ...

  6. HDU 5136 Yue Fei's Battle

    题目链接:HDU-5136 网上的一篇题解非常好,所以就直接转载了.转自oilover的博客 代码: #include<cstring> #include<cstdio> #i ...

  7. HDU 5129 Yong Zheng's Death

    题目链接:HDU-5129 题目大意为给一堆字符串,问由任意两个字符串的前缀子串(注意断句)能组成多少种不同的字符串. 思路是先用总方案数减去重复的方案数. 考虑对于一个字符串S,如图,假设S1,S2 ...

  8. 对list对象进行排序

    List<LjlSevOrdersVO> list = ljlSevOrdersService.findSevForOrders(ljlSevOrdersVO); //查出所有是自愿者的订 ...

  9. 手机端调试console.log,直接引入一个js文件

    http://files.cnblogs.com/files/lwwen/mConsole.js 这是我写的一个原生js文件 直接引入即可,可以把html上面的需要打印的东西打印出来 <!DOC ...

  10. 深入理解计算机(CSAPP)资源汇总

    用于资源记录. 视频: 卡内基梅隆大学 Introduction to Computer Systems CMU 15-213 Fall 作业(labs): Lab Assignments