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引理回忆一下基础知识.总结的很棒. 一个置换就是集合到自身的一个双射,置 ...
随机推荐
- 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)
题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...
- ...args剩余参数用法
剩余参数语法允许我们将一个不定数量的参数表示为一个数组. function sum(...theArgs) { return theArgs.reduce((previous, current) ...
- 生成应用的快捷方式action,权限
action:"com.android.launcher.action.INSTALL_SHORTCUT" 权限:com.android.launcher.permission.I ...
- 【Python学习】程序运行完发送邮件提醒
有时候我们运行一个需要跑很长时间的程序,不管是在云主机还是本地主机上运行,我们都不可能一直守在电脑面前等.所以想到使用邮件来通知提醒. 示例代码如下 # -*- coding: utf-8 -*- # ...
- GOLANG编译安装
GO这个编译器搞的比较混乱,GO本身是汇编+C开发出来的,后来因为觉得自己牛逼,然后用GO语言又写了一次编译器,所以中途抛弃了C,不过这种做法好与不好很难说,go真的这么有自信用自己语言写自己的编译器 ...
- 基数排序c++实现
基数排序:是一种非比较型整数排序算法,其原理是将整数按位数切割成不同的数字,然后按每个位数分别比较.由于整数也可以表达字符串(比如名字或日期)和特定格式的浮点数,所以基数排序也不是只能使用于整数.但在 ...
- JavaScript中常用的BOM属性
window 窗口 window.open():打开窗口.返回一个指向新窗口的引用. window.close():关闭窗口. window.resizeTo():调整窗口尺寸到指定值 window. ...
- php上传文件限制
客户端限制(客户端限制在实际上是无法阻止上传): 通过表单隐藏域限制上传文件的最大值 <input type=’hidden’ name=’MAX_FILE_SIZE’ value=’字节数’ ...
- vue2.0--组件通信(非vuex法)
写在前面: 1.父组件的data写法与子组件的data写法不同 //父组件 data:{ //对象形式 } //子组件 data:function(){ return { //函数形式 } } 2.引 ...
- 五十六 SMTP发送邮件
SMTP是发送邮件的协议,Python内置对SMTP的支持,可以发送纯文本邮件.HTML邮件以及带附件的邮件. Python对SMTP支持有smtplib和email两个模块,email负责构造邮件, ...