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引理回忆一下基础知识.总结的很棒. 一个置换就是集合到自身的一个双射,置 ...
随机推荐
- Python 源码学习之内存管理 -- (转)
Python 的内存管理架构(Objects/obmalloc.c): _____ ______ ______ ________ [ int ] [ dict ] [ list ] ... [ str ...
- ES6新增的let与const
1.const 声明常量,一旦声明必须立马赋值,否则报错 const PI = 3.14 const PI; //报错:Uncaught SyntaxError: Missing initialize ...
- 微信支付:curl 出错,错误码: 60
在测试微信支付 - 模式二 - 扫码支付时,遇到如下错误: curl出错,错误码:60 这是因为在 WxPay.Api.php 文件中做了严格的 ssl 证书校验: curl_setopt($ch,C ...
- $scope作用及模块化解决全局问题
$scope对象就是一个普通的JavaScript对象,我们可以在其上随意修改或添加属性.$scope对象在AngularJS中充当数据模型,但与传统的数据模型不一样,$scope并不负责处理和操作数 ...
- 零基础学php的自学
我们都知道,php语言作为一种专业建站的语言,没有华而不实,而是经受住了时间考验,成为一种值得学习的语言.现在国内众多的php学校也说明,php语言在当今有着广泛的市场需求. 那么零基础的同学如何学习 ...
- hadoop-Rpc使用实例
代码:https://github.com/xufeng79x/hadoop-common-rpc-demo 1. 简介 hadoop中使用rpc机制来进行分布式进程间的通信,被封装进了hadoop- ...
- mongodb实现批量修改数据
var rds = db.REGIPATIENTREC.find({mzh:{$lt:"0"},usrOrg:"石景山中西医结合医院"}); var show ...
- Ruby-Clamp
require "clamp" class ClampTest < Clamp::Command # 1.命令行的参数使用主要分两类,一种是参数名称后面带参数值的方式, #我 ...
- Java初次见面
1.Java语言特点(运行环境JRE[操作系统,api,dll]): a.跨平台:Java自带的虚拟机很好地实现了跨平台性.Java源程序代码经过编译后生成二进制的字节码是与平台无关的,但是可被Jav ...
- java 默认内存大小
https://www.cnblogs.com/jack204/archive/2012/07/02/2572932.html -Xmx Java Heap最大值,默认值为物理内存的1/4,最佳设 ...