HDU 3547 DIY Cube Ploya定理

来源:http://acm.hdu.edu.cn/showproblem.php?pid=3547

题意:用n中颜色涂一个正方体的八个顶点,求有多少种方法。如果得到的结果大于等于10^15,则输出后15位即可。

思路:Ploya定理啊,是组合数学课本上的原题。对应于四种不同类型的旋转,1:不动,即恒等旋转有1个;2:绕三对对立面的中心旋转,有旋转90度,旋转180度,旋转270度,分别有3个;3:绕对边终点连线旋转,有6个;4:绕对角点旋转,有旋转120度和旋转240度,分别有4个。因此共有24个对称。最后可以转化成公式(k^8 + 17*k^4 + 6 * k^2)/ 24 。由于涉及到了大数,所以这道题我使用java写的,唉,不会java,乱搞一通。

代码:

import java.util.*;
import java.math.BigInteger;
public class Main {
	/*
	public static BigInteger pow(int x){
		BigInteger a;
		a=a.pow(12)
	}*/
	public static void main(String[] args){
		int numcase;
		Scanner cin = new Scanner(System.in);
		numcase = cin.nextInt();
		for(int i = 1;i <= numcase;++i){
			BigInteger color,pow8,pow4,pow2;
			color = cin.nextBigInteger();
			pow8 = color.pow(8);
			//System.out.println(pow8);
			pow4 = color.pow(4);
			BigInteger x = new BigInteger("17");
			pow4 = pow4.multiply(x);
			BigInteger y = new BigInteger("6");
			pow2 = color.pow(2);
			pow2 = pow2.multiply(y);
			BigInteger sum = new BigInteger("0");
			sum = sum.add(pow8);
			sum = sum.add(pow4);
			sum = sum.add(pow2);
			BigInteger z = new BigInteger("24");
			sum = sum.divide(z);
		//	System.out.println("sum = "+sum);
			BigInteger p = new BigInteger("10");
			p = p.pow(15);
			System.out.print("Case "+i+": ");
			if(sum.compareTo(p) < 0){
				System.out.println(sum);
			}
			else{
				BigInteger q = sum.mod(p);
				String ss = q.toString();
				int len = ss.length();
				if(len < 15){
					int xx = 15 - len;
					for(int j = 0; j < xx; ++j)
						System.out.print(0);
				}
				System.out.println(q);
			}
		}
	}
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值