Computer Transformation&&http://acm.hdu.edu.cn/showproblem.php?pid=1041

找规律题+大数问题,java一切ok。。。。

AC代码:

import java.math.*;
import java.util.*;
public class Main {

	/**
	 * @param args
	 */
	private static BigInteger [] ans=new BigInteger [1005];
	private static void init()
	{
		ans[1]=BigInteger.valueOf(0);
		ans[2]=BigInteger.valueOf(1);
		ans[3]=BigInteger.valueOf(1);
		 for(int i=4; i<=1000; i++)
	        {
	           
			   ans[i]=ans[i-1].add(ans[i-2].multiply(BigInteger.valueOf(2)));
	        }
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin = new Scanner(System.in);
        init();
        while (cin.hasNext()) {
            int n = cin.nextInt();
            System.out.println(ans[n]);
        }
	}

}


你可能感兴趣的:(Computer Transformation&&http://acm.hdu.edu.cn/showproblem.php?pid=1041)