标签:style blog color 使用 java ar for div sp
POJ1205
递推公式为a[i] = 3*a[i-1] - a[i-2], a[1] = 1,a[2] = 3 , i 最高为100;
搞懂了使用BigInteger开数组。
1 import java.util.*; 2 import java.math.*; 3 4 public class Main 5 { 6 public static void main(String[] args) 7 { 8 Scanner cin = new Scanner(System.in); 9 BigInteger a[] = new BigInteger[101]; 10 a[1] = BigInteger.ONE; 11 a[2] = BigInteger.valueOf(3); 12 BigInteger Three = BigInteger.valueOf(3); 13 for(int i=3; i<=100; i++) 14 a[i] = Three.multiply(a[i-1]).subtract(a[i-2]); 15 while(cin.hasNext()) 16 { 17 int n = cin.nextInt(); 18 System.out.println(a[n]); 19 } 20 } 21 }
标签:style blog color 使用 java ar for div sp
原文地址:http://www.cnblogs.com/catdrivedragon/p/3966354.html