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/ ...
随机推荐
- POJ 1226 Substrings(后缀数组+二分答案)
[题目链接] http://poj.org/problem?id=1226 [题目大意] 求在每个给出字符串中出现的最长子串的长度,字符串在出现的时候可以是倒置的. [题解] 我们将每个字符串倒置,用 ...
- 利用BP神经网络预测水道浅滩演变
论文 <基于现代技术的河道浅滩演变研究> 利用BP神经网络来预测浅滩演变 BP输出因子:浅滩的年平均淤积厚度以及浅滩上最小水深,是反映浅滩变化的两个基本指标,是确定浅滩航道尺度能否满足航行 ...
- DOM ISO - get current element's XPATH
DOM ISO - get current element's XPATH DOM ISO - get current element's XPATH
- Android面试题06
51. 一条最长的短信息约占多少byte? 中文70(包括标点),英文160,160个字节 这个说法不准确, 要跟手机制式运营商等信息有关. 做实验,看源码 ArrayList<String&g ...
- sql的强大功能(看一条sql解决的复杂业务)
一条sql语句解决的复杂业务,请往下看: 业务介绍:一个单位有多个立项(立项信息表里有单位id),每个立项可能被预警多次(预警信息表里的uuid字段的值里包含有立项id或单位id),每 ...
- block 解析 - 内存
block结构体相应的也有一个成员引用,这样会增加对局部变量的 _para1引用,在Block销毁的时候引用就释放掉了 我们了解到了用__block修饰的变量,可以在block内部修改,__block ...
- GDB调试之core文件(如何定位到Segment fault)
core dump又叫核心转储,当程序运行过程中发生异常,程序异常退出时,由操作系统把程序当前的内存状况存储在一个core文件中,叫core dump.(内部实现是:linux系统中内存越界会收到SI ...
- border-radius 知识点
border-radius:50px; 边框半径 CSS度量值都:em.px.百分比如果设置1个值,表示4个圆角都使用这个值.如果设置两个值,表示左上角和右下角使用第一个值,右上角和左下角使用第二个值 ...
- BZOJ 1770: [Usaco2009 Nov]lights 燈( 高斯消元 )
高斯消元解xor方程组...暴搜自由元+最优性剪枝 -------------------------------------------------------------------------- ...
- BZOJ 3223: Tyvj 1729 文艺平衡树(splay)
速度居然进前十了...第八... splay, 区间翻转,用一个类似线段树的lazy标记表示是否翻转 ------------------------------------------------- ...