poj 2094 多项式求和。
/**
给出多项式 p(x) = an*x^n + an-1*x^(n-1)..... + a1*x + a0;
给定n,l,k,m 计算 x 从 l到 l+k-1 的p(x)的后m 位的平方的和 用差分序列 ,先计算出前 n项 构造出差分表。。后边的k-n个 用递推可得,从下往上递推。
**/ import java.math.BigInteger;
import java.util.Scanner; public class Main { public static int cal(String str, int m) {
// System.out.println(str+"------->");
int len = Math.min(str.length(), m);
int ans = , tmp;
for (int i = ; i < len; i++) {
tmp = str.charAt(i) - '';
ans += tmp * tmp;
}
return ans;
} public static void main(String[] args) {
Scanner cin = new Scanner(System. in);
int n = cin.nextInt();
BigInteger l = cin.nextBigInteger();
int k = cin.nextInt();
int m = cin.nextInt();
BigInteger mod = BigInteger. TEN.pow(m);
BigInteger[] a = new BigInteger[];
for (int i = ; i <= n; i++)
a[i] = cin.nextBigInteger();
BigInteger h[][] = new BigInteger[][];
for (int i = ; i < Math.min (n + , k); i++) {
BigInteger res = a[];
for (int j = ; j <= n; j++) {
res = res.multiply(l);
res = res.add(a[j]);
}
res = res.mod(mod);
l = l.add(BigInteger. ONE);
h[][i] = res;
System. out.println(cal(res.toString(), m));
} if (k > n + ) {
for (int i = ; i <= n; i++) {
for (int j = ; j <= n - i; j++)
h[i][j] = h[i - ][j + ].subtract(h[i - ][j]);
}
} BigInteger pre[] = new BigInteger[];
for (int i = ; i <= n; i++) {
pre[i] = h[i][n - i];
}
for (int i = n + ; i < k; i++) {
BigInteger res = h[n][];
for (int j = n - ; j >= ; j--) {
res = pre[j].add(res);
res = res.mod(mod);
pre[j] = res;
}
System. out.println(cal(res.toString(), m));
}
} }
poj 2094 多项式求和。的更多相关文章
- HDOJ2011多项式求和
多项式求和 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 多项式求和 AC 杭电
多项式求和 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- 多项式求和,素数判定 HDU2011.2012
HDU 2011:多项式求和 Description 多项式的描述如下: 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + ... 现在请你求出该多项式的前n项的和. Input ...
- SDUT OJ 多项式求和
多项式求和 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description 多项式描述 ...
- hdu2011 多项式求和【C++】
多项式求和 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- Java练习 SDUT-2504_多项式求和
多项式求和 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 多项式描述如下: 1 - 1/2 + 1/3 - 1/4 + ...
- 练习2 J题 - 多项式求和
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 多项式 ...
- HDOJ 2011 多项式求和
Problem Description 多项式的描述如下: 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + - 现在请你求出该多项式的前n项的和. Input 输入数据由2行组成, ...
- HDU 2011 多项式求和
http://acm.hdu.edu.cn/showproblem.php?pid=2011 Problem Description 多项式的描述如下:1 - 1/2 + 1/3 - 1/4 + 1/ ...
随机推荐
- SQL Server 2012学习笔记 1 命令行安装
setup.exe /Q /IACCEPTSQLSERVERLICENSETERMS /ACTION=install /PID=748RB-X4T6B-MRM7V-RTVFF-CHC8H /FEATU ...
- SSIS: 使用Lookup 和 Cache transformation 进行数据匹配简单介绍
本文将讲解Cache transformation的使用方式,并且用Lookup transformation进行匹配. 背景 如下图,我们的产品目标表中有些有尺寸信息有些没有.我们需要用Cache组 ...
- 1.3. chromium源代码分析 - chromiumframe - 窗口系列
在_tWinMain中有这样两条语句: MainWindowDelegate delegate; view::Window::CreateNativeWindow(NULL, gfx::Rect(), ...
- POJ 3974 Palindrome(最长回文子串)
题目链接:http://poj.org/problem?id=3974 题意:求一给定字符串最长回文子串的长度 思路:直接套模板manacher算法 code: #include <cstdio ...
- AC自动机妙用
理解题意之后,很自然的想到了用AC自动机搞,结果网上一搜,全是暴搜,按照自己的思想,AC自动机搞起,果然在提交了数次之后,看到了Accept. AC自动机需要三个步骤: 第一步:建立字典树: 第二步: ...
- BZOJ 1051: [HAOI2006]受欢迎的牛( tarjan )
tarjan缩点后, 有且仅有一个出度为0的强连通分量即answer, 否则无解 ----------------------------------------------------------- ...
- PHP PDO select语句结果行数计算
PDO有一个函数PDOStatement::rowCount返回上一个SQL语句影响的行数. rowCount函数对于DELETE, INSERT, 或者UPDATE语句的结果是正确的,但对于sele ...
- Python 第三篇(上):python文件基础操作、json模块、lambda、map、filter、reduce和函数位置参数
python一切皆对象,linux一切皆文件,python操作文件是很常见的O/I操作,其内置来open()函数可以完成文件的基本操作: 一:使用内置open()函数操作文件,基本语法如下: with ...
- BZOJ 1874 取石子游戏 (NIM游戏)
题解:简单的NIM游戏,直接计算SG函数,至于找先手策略则按字典序异或掉,去除石子后再异或判断,若可行则直接输出. #include <cstdio> const int N=1005; ...
- Linux 下的多线程编程
随着你对编程的深入,多线程是一个免不了的话题,在这里就对多线程做一个比较详细的总结. 首先摆在我们面前的就是什么是线程,以及为么会有这个东西.记得之前学习的时候自己会画一张很大的图,在图中可以详细的写 ...