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 Leo at 2005-10-23 13:52:10 on Problem 2680
In Reply To:Re:不行!!大侠帮忙看看! Posted by:Leo at 2005-10-23 13:36:36
import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main
{
    public static void main(String args[])throws Exception
    {
        String input;
        int number=0;
        BigInteger array[]=new BigInteger[1001];
        array[1]=new BigInteger("0");
        array[2]=new BigInteger("1");
        BigInteger one=new BigInteger("1");
        BigInteger two=new BigInteger("2");
        for(int i=3;i<=1000;i++)
        {
		       if(i%2==0)
		       {
		            array[i]=array[i-1].multiply(two);
		            array[i]=array[i].add(one);
		       }
		       else
		       {
		            array[i]=array[i-1].multiply(two);
		            array[i]=array[i].subtract(one);
               }
		}
        while(true)
        {
            try
            {
            	Scanner cin=new Scanner(System.in);
            	if(cin==null) break;
            	number=cin.nextInt();
            }
            catch(Exception e)
            {
                break;
            }
            if(number==1)
            {
                System.out.println("0");
            }
            else if(number==2)
            {
                System.out.println("1");
            }
            else
            {
               System.out.println(array[number]);
            }

        }
    }
}


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