Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Java的BigInteger很好很强大。。。不是时间和内存占用率也很强大。。。附AC代码Source Code Problem: 1090 User: yzhw Memory: 5344K Time: 1829MS Language: Java Result: Accepted Source Code import java.math.*; import java.io.*; public class Main { /** * @param args */ static boolean[] data; static BigInteger std[]; static BigInteger zero=new BigInteger("0"),one=new BigInteger("1"),two=new BigInteger("2"); static BigInteger to1(int num) { if(num==1) { if(data[1]) return zero; else return one; } else { if(data[num]) { return to0(num-1); } else { return to1(num-1).add(one).add(std[num-1]); } } } static BigInteger to0(int num) { if(num==1) { if(data[1]) return one; else return zero; } else { if(data[num]) { return to1(num-1).add(one).add(std[num-1]); } else { for(int i=num;i>=1;i--) if(data[i]) return to0(i); return to0(1); } } } public static void main(String[] args) throws IOException{ StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); int num; in.nextToken(); num=(int)in.nval; data=new boolean[num+1]; std=new BigInteger[num+1]; std[1]=new BigInteger("1"); for(int i=2;i<=num;i++) { std[i]=new BigInteger(std[i-1].toString()).multiply(two).add(one); } for(int i=1;i<=num;i++) { int temp; in.nextToken(); temp=(int)in.nval; data[i]=(temp==1?true:false); } System.out.println(to0(num).toString()); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator