hdu 4927 Series 1(JAVA大数)

来源:互联网 发布:掌上电力用电数据同步 编辑:程序博客网 时间:2024/06/06 03:25

题目很简单: 找规律即可

这题明显是要JAVA大数写的。。 不过比赛的时候WA了两次才反应过来的。 尽管后来还是A了,, 不过写了好久。。。。

太久没写JAVA,感觉对JAVA好陌生了

 

代码:

package main;import java.math.BigInteger;import java.util.*;public class Main {public static void main(String[] args){Scanner sc= new Scanner(System.in);BigInteger[] big= new BigInteger[3006];int t= sc.nextInt();for(int T= 1; T<= t; T++){int n= sc.nextInt();int a[]= new int[3006];for(int i= 1; i<= n; i++)a[i]= sc.nextInt();big[0]= big[0].valueOf(1);BigInteger aa= new BigInteger("0");BigInteger bb= new BigInteger("0");BigInteger cc= new BigInteger("0");BigInteger ans= new BigInteger("0");BigInteger flag= new BigInteger("0");aa= aa.valueOf(0);bb= bb.valueOf(n);cc= cc.valueOf(1);for(int i= 1; i< n; i++){aa= aa.add(cc);bb= bb.subtract(cc);big[i]= (big[i-1].multiply(bb)).divide(aa);}ans= ans.valueOf(0);for(int i= n, j= 0; i>= 1; i--,j++){if(j%2==0)flag= flag.valueOf(a[i]);elseflag= flag.valueOf(-a[i]);ans= ans.add(flag.multiply(big[j]));}System.out.println(ans);}}}

0 0
原创粉丝点击