您的位置:首页 > 其它

BZOJ 1263: [SCOI2006]整数划分

2012-12-18 12:01 169 查看
/*
* 分析:
* 贪心+高精度。。。尽量凑3,不足凑2
*
* */

http://www.lydsy.com/JudgeOnline/problem.php?id=1263

import java.util.Scanner;
import java.math.*;

public class Main{
public static void main(String [] args){
BigInteger ans;
BigInteger th = BigInteger.valueOf(3);
int n;

Scanner cin = new Scanner(System.in);

while(cin.hasNext()){
n = cin.nextInt();
if(n==1){
System.out.println(1);
System.out.println(1);
continue;
}
ans = BigInteger.ONE;
int three = 0;
while(n>4){
three ++;
n -= 3;
}
if(n==4||n==2)
ans = ans.multiply(BigInteger.valueOf(n));
else if(n==3)
three ++;
for(int i=0;i<three;i++)
ans = ans.multiply(th);
String s = ans.toString();
System.out.println(s.length());
if(s.length()>100){
for(int i=0;i<100;i++)
System.out.print(s.charAt(i));
System.out.println();
}
else
System.out.println(ans);
}
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: