http://acm.hdu.edu.cn/showproblem.php?pid=4927

同学用java写的大整数相减

Series 1

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 295    Accepted Submission(s): 100

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
2
3
1 2 3
4
1 5 7 2
 
Sample Output
0
-5
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);
}
}
}
 

HDU-4927 Series 1的更多相关文章

  1. HDU 4927 Series 1(推理+大数)

    HDU 4927 Series 1 题目链接 题意:给定一个序列,要求不断求差值序列.直到剩一个,输出这个数字 思路:因为有高精度一步.所以要推理一下公式,事实上纸上模拟一下非常easy推出公式就是一 ...

  2. HDU 4927 Series 1 ( 组合+高精度)

    pid=4927">Series 1 大意: 题意不好翻译,英文看懂也不是非常麻烦,就不翻译了. Problem Description Let A be an integral se ...

  3. HDU 4927 Series 1(高精度+杨辉三角)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4927 解题报告:对于n,结果如下: C(0,n-1) *A[n] - C(1,n-1) * A[n-1 ...

  4. 2014多校第六场 1007 || HDU 4927 Series 1(杨辉三角组合数)

    题目链接 题意 : n个数,每操作一次就变成n-1个数,最后变成一个数,输出这个数,操作是指后一个数减前一个数得到的数写下来. 思路 : 找出几个数,算得时候先不要算出来,用式子代替,例如: 1 2 ...

  5. 多校第六场 HDU 4927 JAVA大数类+模拟

    HDU 4927 −ai,直到序列长度为1.输出最后的数. 思路:这题实在是太晕了,比赛的时候搞了四个小时,从T到WA,唉--对算组合还是不太了解啊.如今对组合算比較什么了-- import java ...

  6. 【HDU - 4927】Series 1

    BUPT2017 wintertraining(15) #5I 题意 输出序列A[1..n]的第n-1阶差分(一个整数). 题解 观察可知答案就是 \[ \sum_{i=0}^{n-1} {(-1)^ ...

  7. HDU 4927

    http://acm.hdu.edu.cn/showproblem.php?pid=4927 直接模拟会超时,要在纸上写写推公式 A[n]*C(0,n-1)  - A[n-1]*C(1,n-1) + ...

  8. hdu 4927 组合+公式

    http://acm.hdu.edu.cn/showproblem.php?pid=4927 给定一个长度为n的序列a,每次生成一个新的序列,长度为n-1,新序列b中bi=ai+1−ai,直到序列长度 ...

  9. hdu 4928 Series 2 (优化+模拟)

    题意: 一个含n个数的序列a,每两个相邻的数相减得到一个新数,这些数组成一个新的序列. 假设全部得到的序列都满足非严格的单调性.则原序列为nice series.假设给出的序列 本来不满足单调性.它是 ...

  10. HDU 4928 Series 2

    有了题解以后这题就成了一个模拟题.不过写了好久才把它写对…… Sad #include <iostream> #include <cstdio> #include <cs ...

随机推荐

  1. 使用html5兼容低版本浏览器

    因为html5 新出的一些语义化的标签,在低版本浏览器下不能识别,举个例子,比如你写了一个 header 标签中,写了一段文本,在低版本浏览器下,肯定是能看到的,但是,那是他是不认识 header标签 ...

  2. IIS 上发布ASP.NET5

    原文 http://docs.asp.net/en/latest/publishing/iis.html 1.安装HTTP Platform Handler ,这个是必需的,不然无法通过IIS访问AS ...

  3. javascript 动态操作Html

    <html> <body> <p>aaaaa</p> <input type="button" value="con ...

  4. CoreAnimation实现一个折线表

    将折现表封装到一个view里,暴露给使用者的只有一个传入数据的方法. // // ChartLine.h // BoxingChampion //功能:根据传入的数组,绘制折线图 注意 其frame的 ...

  5. 配置wamp开发环境【1】

    新手在PHP网站建设时,会使用使用PHP的集成开发环境,这样利于开发和理解!但是做为一个网站开发人员,会独立的配置开发环境这是必须的……因为集成的环境毕竟是固定的,不利于自己的开发.好,废话少说咱现在 ...

  6. cocos2dx 实现不一样的ScrollView

    原来在公司被迫加班加点赶工,用lua实现的版本:http://www.cnblogs.com/mmc1206x/p/4146911.html 后来因我个人的需要, 用C++实现了一个版本. 蓦然回首, ...

  7. asp.net treeview控件无刷新选择和删除节点的ajax方法

    转载 http://blog.csdn.net/luq885/article/details/1621681 如果节点被选择的话,节点所在的td的class属性就会被设置为TreeView1_1.   ...

  8. easyui-combobox小Demo

    <script type="text/javascript"> $("#Function_TypeSelect").combobox({ onSel ...

  9. ext 扩展控件—moneyField

    /** *数字控件 *带大写提示,和千分位 **/ Ext.define(appNameSpace+'.utils.MoneyField', { extend : 'Ext.form.field.Te ...

  10. mysql datestamp坑

    每次更改行数据,该行第一个datestamp如不赋值,会自动更新为当前时间.赋值还要注意用下new Date(time).updated_at要写在created_at前面...