HDU4927:Series 1(JAVA大数)

来源:互联网 发布:淘宝账号手机登录界面 编辑:程序博客网 时间:2024/06/03 22:39
Problem Description
Let A be an integral series {A1, A2, . . . , An}.

The zero-order series of A is A itself.

The first-order series of A is {B1, B2, . . . , Bn-1},where Bi = Ai+1 - Ai.

The ith-order series of A is the first-order series of its (i - 1)th-order series (2<=i<=n - 1).

Obviously, the (n - 1)th-order series of A is a single integer. Given A, figure out that integer.
 

Input
The input consists of several test cases. The first line of input gives the number of test cases T (T<=10).

For each test case:
The first line contains a single integer n(1<=n<=3000), which denotes the length of series A.
The second line consists of n integers, describing A1, A2, . . . , An. (0<=Ai<=105)
 

Output
For each test case, output the required integer in a line.
 

Sample Input
231 2 341 5 7 2
 

Sample Output
0-5
开始没考虑太多,直接暴力一交,WA
暴力最多超时,怎么WA呢,第一个想法就是,大数
大数怎么能忘记JAVA呢?C++写大数太麻烦了,果断JAVA变成水题
import java.math.BigInteger;import java.util.*;import java.io.*;public class Main {    public static void main(String args[]) {        Scanner in = new Scanner(System.in);        int t = in.nextInt();        int a[] = new int[3005];        for (int cas = 1; cas <= t; cas++) {            int n = in.nextInt();            int  i, j;            for (i = 1; i <= n; ++i) {                a[i] = in.nextInt();            }            BigInteger ans = BigInteger.valueOf(a[n]);            BigInteger x = BigInteger.valueOf(1);            BigInteger flag = BigInteger.valueOf(-1);            n = n -1;            for(i=1,j=n; i<=n; i++,j--)            {                x = x.multiply(BigInteger.valueOf(j)).divide(BigInteger.valueOf(i));                x = x.multiply(flag);                ans = ans.add(x.multiply(BigInteger.valueOf(a[j])));            }            System.out.println(ans);        }    }}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 顾客恶意差评怎么办 淘宝不能看视频怎么办 天猫精灵打不开怎么办 手机淘宝卡死了怎么办 为什么电视盒子打不开怎么办 天猫买了降价了怎么办 试用报告未提交怎么办 试用中心拉黑怎么办 淘宝赠品破了怎么办 淘宝卖家不给赠品怎么办 淘宝赠品有瑕疵怎么办 淘宝赠品不发货怎么办 移动电视没信号怎么办 网络电视死机了怎么办 电视接收网络信号不好怎么办 tcl电视待机打不开怎么办 宽带电视看不了怎么办 电视总是闪退怎么办 电视出现系统更新怎么办 电视一直在更新怎么办 电视更新死机了怎么办 法院打电话不接怎么办 内向不敢辞职怎么办呀 生气后睡不着觉怎么办 被气得睡不着怎么办 一生气就睡不着怎么办 手机接电话声音小怎么办 发微信老公不回怎么办 欠钱没有欠条怎么办 朋友欠钱不还怎么办没欠条 个人欠销售货款怎么办 货款一直不还怎么办 欠钱不接电话找不到人怎么办 欠钱人电话不接怎么办 客户欠款不给怎么办 客户货款打一半怎么办 欠款人不到庭怎么办 别人打电话不接怎么办 百合注册被禁用怎么办? 监控显示未登录怎么办 发票认证了两次怎么办