hdu 1131 Count the Trees

卡特兰数*阶乘就是答案     第一次用java。。高精度写起来好快。。。。不过代码比较丑。。

import java.math.BigInteger;
import java.util.Scanner;
  
public class Main
{  
    public static void main(String []args)
    {  
        Scanner cin = new Scanner(System.in);  
        int i,ii;
        BigInteger []c= new BigInteger[105];
        BigInteger []jie= new BigInteger[105];
        BigInteger linshi2;
        c[0]=new BigInteger("1");
        for(i=1;i<=100;i++)
        {
            int u=4*i+2;
            String str=String.valueOf(u);
            BigInteger ww=new BigInteger(str);
            linshi2=c[i-1].multiply(ww);
            u=i+2;
            String strr=String.valueOf(u);
            BigInteger www=new BigInteger(strr);
            c[i]=linshi2.divide(www);
        } 
        jie[1]=new BigInteger("1");
        for(ii=2;ii<=100;ii++)
        {
            int ef=ii;
            String trt=String.valueOf(ef);
            BigInteger rr=new BigInteger(trt);
            jie[ii]=rr.multiply(jie[ii-1]);
        }
        while(cin.hasNext())
        {
            int pp=cin.nextInt();
            if(pp==0) break;     
            System.out.println(c[pp-1].multiply(jie[pp]));
        }
    }  
}

 

posted @ 2015-05-04 16:15  Fighting_Heart  阅读(168)  评论(0编辑  收藏  举报