题目链接:

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. Web安全扫描工具

    使用 Ibm security appscan  进行WEB安全扫描. 1.SQL注入: 2.发现内部IP泄露模式: 3.已解密的登录请求: 4.HTML注释敏感信息泄露:

  2. Python Study (01) 之 特殊方法

    Python深入:特殊方法和多范式 Python是一切皆对象,意思就是python的天生就是个"纯面向对象语言"呀. 但是!!! Python还是一个多范式语言(multi-par ...

  3. Window7幻灯片字体显示混乱,难道真的是病毒么

    这个问题有几天了.就是在其它人的PowerPoint2010做的ppt文件.发到这台有问题的电脑上(PowerPoint2007)就会显示全然不一样.例如以下所看到的. watermark/2/tex ...

  4. [叁]Pomelo游戏server编程分享 之 server结构与配置分析

    网络部署结构 我们先看一下Pomeloserver网络部署情况,直接上图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3RiaW56aQ==/font/ ...

  5. 深入浅出CChart 每日一课——快乐高四第九课 于无声处,CChart内置功能介绍之数据存取篇

    笨笨长期以来一直使用Origin软件画图和处理数据,但Origin软件没有编程语言的接口.笨笨开发CChart的一个潜在的目标.是想实现Origin软件的功能.当然这是一个不可能达到的目标.Origi ...

  6. Android 零基础学习之路

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

  7. Android系统编译【转】

    本文转载自;http://blog.csdn.net/zirconsdu/article/details/8005415 Android编译系统分析 概要 由于android编译系统的复杂和使用了不熟 ...

  8. 5.listview(QStringList QStringListModel)

    UI mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include < ...

  9. ES6 | ES6新语法 在编码实践中的应用

    本章探讨如何将 ES6 的新语法,运用到编码实践之中,与传统的 JavaScript 语法结合在一起,写出合理的.易于阅读和维护的代码. 多家公司和组织已经公开了它们的风格规范,本文的内容主要参考了  ...

  10. Windows 安装 MySQL8

    MySQL8下载地址:https://dev.mysql.com/downloads/mysql/ 解压到安装目录 新建配置文件my.ini [mysqld]# 设置mysql的安装目录basedir ...