Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

附毛,炫耀呢吧

Posted by Pzjay at 2010-05-27 19:00:53 on Problem 1090
In Reply To:Java的BigInteger很好很强大。。。不是时间和内存占用率也很强大。。。附AC代码 Posted by:yzhw at 2009-07-01 10:40:32
> 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator