题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3547
题意是让我们用n中颜色去填涂一个立方体的8个顶点,问我们最多可以有多少种填涂方法。
很明显的一个Pólya定理(不懂Pólya定理的同学,欢迎观看小编另一篇博客)的问题。
我们先来分析所有的置换。
1.沿着一组对面的中心旋转(*3):
90度:2个循环节。
180度:4个循环节。
270度:2个循环节。
2.沿着一组对边的中心旋转(*6):
180度(只能180度旋转):4个循环节。
3.沿着一组体对角线旋转(*4):
120度:4个循环节。
240度:4个循环节。
综上24种置换,我们可以得到答案为(n^8 + 6*n^2 + 17*n^4)。
PS.此题是一个大数问题。
import java.io.*;
import java.math.*;
import java.util.*;
import java.text.*;
public class Main {
public static BigInteger polya (BigInteger N, BigInteger C) {
int n = N.intValue();
BigInteger ret = C.pow(8);
ret = ret.add(C.pow(2).multiply(BigInteger.valueOf(6)));
ret = ret.add(C.pow(4).multiply(BigInteger.valueOf(17)));
return ret.divide(BigInteger.valueOf(24));
}
public static void main(String[] args) {
Scanner cin = new Scanner(new BufferedInputStream(System.in));
int T, cas, len;
T = cin.nextInt();
BigInteger C, ret;
String str;
for(cas=1;cas<=T;cas++){
C = cin.nextBigInteger();
ret = polya(BigInteger.valueOf(8),C);
str = ret.toString();
len = str.length();
System.out.printf("Case %d: ", cas);
if(len<=15) System.out.println(str);
else{
char [] ch = str.toCharArray();
for(int i=len-15;i<len;i++)
System.out.printf("%c", ch[i]);
System.out.println();
}
}
}
}