题目链接:

Series 1

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 423    Accepted Submission(s): 146
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
 
Source

题目分析:

公式:C(n-1,0)*a[n]-C(n-1,1)*a[n-1]+C(n-1,2)*a[n-2]+...+C(n-1,n-1)*a[n]。

用C(n,k)=C(n,k-1)*(n-k+1)/k就可以高速得到一行的二项式系数。

第一道Java题!

代码例如以下:
import java.util.Scanner;
import java.math.BigInteger; public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
BigInteger[] a;
a = new BigInteger[3017];
int t, n;
t = cin.nextInt(); while(t--){
n = cin.nextInt(); for (int i = 0; i < n; i++)
a[i] = cin.nextBigInteger(); BigInteger ans = BigInteger.ZERO;
BigInteger c = BigInteger.ONE; for (int i = 0; i < n; i++) {
BigInteger tmp = c.multiply(a[n-i-1]); if (i%2 == 0)
ans = ans.add(tmp);
else
ans = ans.subtract(tmp); tmp = c.multiply(BigInteger.valueOf(n-i-1));
c = tmp.divide(BigInteger.valueOf(i+1));
} System.out.println(ans);
}
}
}

hdu4927 Series 1(组合+公式 Java大数高精度运算)的更多相关文章

  1. JAVA BigDecimal 高精度运算

    文章参考一位博友,由于时间太久忘了链接,见谅! public class BigDecimalUtils { private static final int DIV_SCALE = 10;// 除法 ...

  2. java大数

    java大数还是很好用的! 基本加入: import java.math.BigInteger; import jave.math.BigDecimal; 分别是大数和大浮点数. 首先读入可以用: S ...

  3. Java 大数、高精度模板

    介绍: java中用于操作大数的类主要有两个,一个是BigInteger,代表大整数类用于对大整数进行操作,另一个是BigDecimal,代表高精度类,用于对比较大或精度比较高的浮点型数据进行操作.因 ...

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

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

  5. HDOJ(HDU) 2519 新生晚会(组合公式)

    Problem Description 开学了,杭电又迎来了好多新生.ACMer想为新生准备一个节目.来报名要表演节目的人很多,多达N个,但是只需要从这N个人中选M个就够了,一共有多少种选择方法? I ...

  6. HDU5047Sawtooth(java大数)

    HDU5047Sawtooth(java大数) 题目链接 题目大意:在一个矩形内画n个"M".问如何画可以把这个矩形分成最多的区域. 给出这个区域的数目. 解题思路:最好的方式就是 ...

  7. JAVA大数类

    JAVA大数类api http://man.ddvip.com/program/java_api_zh/java/math/BigInteger.html#method_summary 不仅仅只能查J ...

  8. HDU4762(JAVA大数)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. Java 大数类BigInteger和BigDecimal的基本函数

    在Java中有两个类BigInteger和BigDecimal分别表示不可变的任意精度的整数和不可变的有符号的任意精度的十进制数(浮点数).主要用于高精度计算中.这两个类使得java中的大数,高精度运 ...

随机推荐

  1. easy-ui采坑事件

    新用户首次登陆修改密码 imput标签中使用easyui自带的class="easyui-passwordbox"可以是密码隐藏变成黑点但是无法禁用输入法,然后果断的加了一个typ ...

  2. 日志log配置理解

    实际生产中,每天都有大量的日志生成,单个文件(FileAppender)已经不能满足要求,RollingFileAppender继承了FileAppender,并提供了更多的功能: 每天生成一个日志文 ...

  3. HDU 4345

    细心点想,就明白了,题目是求和为N的各数的最小公倍数的种数.其实就是求N以内的各素数的不同的组合(包含他们的次方),当然,是不能超过N的.用Dp能解决.和背包差不多. #include <ios ...

  4. [HTML5] Why ARIA?

    For some reason, you build a custom checkbox component, if without ARIA in mind, basiclly this site ...

  5. android 分享到QQ空间的全部操作

    http://wiki.open.qq.com/wiki/mobile/SDK下载   <!-- QZone分享必须加上以下两个activity -->                &l ...

  6. linux启动器文件(快捷方式)的制作方法

    众所周知.和windows不同,linux的软件安装方式是五花八门的= = 实用sh脚本写的,有tar包自己编译的.有rpm格式的,有deb的,有各种奇葩路径然后+chmod权限执行的.还有改各种配置 ...

  7. Android 零基础学习之路

    第一阶段:Java面向对象编程 1.Java基本数据类型与表达式,分支循环. 2.String和StringBuffer的使用.正則表達式. 3.面向对象的抽象.封装,继承,多态.类与对象.对象初始化 ...

  8. sql server 数据库展开变慢

    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/99bbcb47-d4b5-4ec0-9e91-b1a23a655844/ssms-2 ...

  9. js接收文件流并下载

    js接收文件流并下载 标签(空格分隔): js 在此输入正文 <script type="text/javascript"> function download(fil ...

  10. BZOJ 3674/BZOJ 3673 主席树

    思路: 主席树维护可持久化数组 剩下的就是普通的并查集了- //By SiriusRen #include <cstdio> #include <cstring> #inclu ...