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. ionic 项目分享【转】

    写在文章前:由于最近研究ionic框架,深感这块的Demo寥寥可数,而大家又都藏私,堂堂天朝,何时才有百家争鸣之象,开源精神吾辈当仁不让! 由于昨晚找资料太匆匆 忘记出处了,记得是在http://bb ...

  2. 《高性能js》读书笔记

    第一章:加载和执行 .浏览器的JavaScript的引擎是编译器层的优化: .当浏览器执行JavaScript代码时,不能同时做其他任何事情(单一进程),意味着 .主流浏览器都允许并行下载JS. .减 ...

  3. PHP 内存的分布问题

    php运行,内存分为5个区域, 1.基本数据类型--->栈区 2.符合数据类型-->堆区 对象实例在堆区,对象名字在栈区(指向此对象实例的变量)

  4. java web hello world

    首先在eclipse 里面创建一个java 动态项目, 记住路径,这里是直接通过根目录直接访问的webContent目录下面 的文件, 创建好后 ,在本地配置Tomcat服务器, 将server加入到 ...

  5. java 基本知识点学习

    1 基本数据类型 整型4种:byte 1个字节:short 2个字节:int 4个字节:long 8个字节. 浮点型:float 4个字节;double 8个字节: 布尔型:boolean   tru ...

  6. javascript - 图片的幻灯片效果

    javascript 代码: <script type="text/javascript"> function select_play() { var select_p ...

  7. CI 笔记 数据库

    demo: 1.  建立数据库,driver, 字段 name,telphone,idcard,car,content 2. 建立model,Driver_model.php文件, 建立add方法, ...

  8. iOS截屏代码

    转载自:http://m.open-open.com/m/code/view/1420469506375 1.普通界面 /** *截图功能 */ -(void)screenShot{ UIGraphi ...

  9. 4 C#和Java 的比较

    2007年11月1日    1.访问控制方面:C#有public.internal.protected.private,比java多了个internal,其实它跟java的包访问差不多,interna ...

  10. 站点下的GridView的RowCommand事件的设置,与站点应用不一样

    <ItemTemplate>                                                                    <%--<a ...