标签:blog io os ar java for div c log
卡特兰数的例题了。
import java.math.BigDecimal; import java.math.BigInteger; import java.util.Scanner; import java.io.InputStreamReader; public class Main{ public static void main(String args[]){ Scanner in=new Scanner(System.in); BigDecimal []Can=new BigDecimal[50]; Can[0]=new BigDecimal(1); BigDecimal B,C,D,E; for(int i=1;i<50;i++){ B=new BigDecimal(4*i-2); C=new BigDecimal(i+1); D=Can[i-1].multiply(B); Can[i]=D.divide(C); } int kase=0; E=new BigDecimal(2); while(in.hasNext()){ kase++; int x=in.nextInt(); if(x==-1) break; BigDecimal ans=Can[x].multiply(E); System.out.println(kase+" "+x+" "+ans.toString()); } } }
标签:blog io os ar java for div c log
原文地址:http://www.cnblogs.com/jie-dcai/p/4009071.html