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. 【BZOJ】2502 清理雪道

    [算法]有源汇上下界最小流 [题解]上下界 初看以为是最小覆盖,发现边可以重复经过,不对. 要求所有边都经过……那就下界为1,上界为inf的可行流. 源汇……S连入度为0的点,T连出度为0的点?(反正 ...

  2. UITableView---iOS-Apple苹果官方文档翻译

    本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址  //转载请注明出处--本文永久链接:http://www.cnblogs.com/C ...

  3. Spring理论基础-控制反转和依赖注入

    第一次了解到控制反转(Inversion of Control)这个概念,是在学习Spring框架的时候.IOC和AOP作为Spring的两大特征,自然是要去好好学学的.而依赖注入(Dependenc ...

  4. 打印菱形(c语言)

    #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> int main() { // 定 ...

  5. elementui input样式覆盖 头部小图等

    .nav-right >>> .keywords .el-input__inner { -webkit-appearance: none; background-color: #F3 ...

  6. ES6新用法

    ES6 详细参考页面 简介 ECMAScript和JavaScript的关系是,前者是后者的规格,后者是前者的一种实现.一般来说,这两个词是可以互换的. let命令 ES6新增了let命令,用来声明变 ...

  7. JavaWeb使用Session防止表单重复提交

    在平时开发中,如果网速比较慢的情况下,用户提交表单后,发现服务器半天都没有响应,那么用户可能会以为是自己没有提交表单,就会再点击提交按钮重复提交表单,我们在开发中必须防止表单重复提交. 1.什么是表单 ...

  8. Exploring Qualcomm's TrustZone Implementation

    转自  http://bits-please.blogspot.com/2015/08   (需要FQ, 狗日的墙) In this blog post, we'll be exploring Qua ...

  9. C# 使用HttpWebRequest Post提交数据,携带Cookie和相关参数示例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. Tomcat debug模式下特别慢但是run正常处理方法

    转载自:http://blog.csdn.net/builderwfy/article/details/50785749 到网上查资料发现这是由eclipse和tomcat交互时,在debug模式启动 ...