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位,数字也过大,用大数与小数的高精度去处理。

下面给出代码: 

 

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #define clr(x) memset(x,0,sizeof(x))
 5 #define cop(x,y) memcpy(x,y,sizeof(y))
 6 #define LL long long
 7 #define lim 10
 8 using namespace std;
 9 LL ans[1000];
10 LL xpow[1000];//x的幂
11 LL dv[1000];//x^(i/2)的系数
12 int dd[5]={0,6,17,0,1};
13 void add(LL *a,LL *b);//高精加
14 void mul(LL *a,int b);//高精乘
15 void div(LL *a,int b);//高精除
16 int main()
17 {
18     int T,x;
19     scanf("%d",&T);
20     for(int t=1;t<=T;t++)
21     {
22         scanf("%d",&x);
23         printf("Case %d: ",t);
24         clr(ans);
25         clr(xpow);
26         xpow[0]=1;
27         for(int i=1;i<=8;i++)
28         {
29             mul(xpow,x);
30             if(i%2==0)
31             {
32                 cop(dv,xpow);
33                 mul(dv,dd[i/2]);
34                 add(ans,dv);
35             }
36         }
37         div(ans,24);
38         int v=500;
39         while(ans[v]==0 && v>=1)
40             v--;
41         if(v>14) v=14;
42         for(int i=v;i>=0;i--)
43             printf("%d",ans[i]);
44         printf("\n");
45     }
46     return 0;
47 }
48 void mul(LL *a,int b)
49 {
50     LL ret=0;
51     int v=500;
52     while(a[v]==0 && v>=1)
53         v--;
54     for(int i=0;i<=v || ret!=0;i++)
55     {
56         ret=ret/lim+a[i]*(LL)b;
57         a[i]=ret%lim;
58     }
59     return ;
60 }
61 void add(LL *a,LL *b)
62 {
63     LL ret=0;
64     int v=500;
65     while(a[v]==0 && b[v]==0 && v>=1)
66         v--;
67     for(int i=0;i<=v || ret!=0;i++)
68     {
69         ret=ret/lim+a[i]+b[i];
70         a[i]=ret%lim;
71     }
72     return ;
73 
74 }
75 void div(LL *a,int b)
76 {
77     LL ret=0;
78     int v=500;
79     while(a[v]==0 && v>=1)
80         v--;
81     for(int i=v;i>=0;i--)
82     {
83         ret=ret*lim+a[i];
84         a[i]=ret/(LL)b;
85         ret%=(LL)b;
86     }
87     return ;
88 }

 

 

 

 

 

 

posted @ 2016-08-31 21:39  hk_lin  阅读(350)  评论(0编辑  收藏  举报