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/ ...
随机推荐
- zoj 1004 dfs
想多了!以为一直dfs所有的情况会超时,所以直接忽略了,就自己想了一个优化的算法,最后测试结果对了,但是wa了,自己写算法很容易考虑不周的,还是在最后没有办法的时候在考虑自己的算法吧!!!简单的dfs ...
- U3D 自带navmesh自动寻路教学
网易博客转载 博主:啊赵 unity自带寻路Navmesh入门教程(一) 说明:从今天开始,我阿赵打算写一些简单的教程,方便自己日后回顾,或者方便刚入门的朋友学习.水平有限请勿见怪.不过请尊重码字截图 ...
- Android应用开发提高篇(3)-----传感器(Sensor)编程
链接地址:http://www.cnblogs.com/lknlfy/archive/2012/02/29/2373420.html 一.概述 Android支持的传感器种类越来越多了,这确实是一件可 ...
- POJ 3167 Cow Patterns(模式串浮动匹配)
题目链接:http://poj.org/problem?id=3167 题意:模式串可以浮动的模式匹配问题给出模式串的相对大小,需要找出模式串匹配次数和位置. 思路:统计比当前数小,和于当前数相等的, ...
- 无法在web服务器上启动调试,服务器不支持对ASP.NET 或ATL Server应用程序进行调试。
无法在web服务器上启动调试,服务器不支持对ASP.NET 或ATL Server应用程序进行调试. a>.DCOM配置里的属性灰色不可用的解决方法, 1>.管理工具->组件服务 ...
- 宣布正式发布 Windows Azure 多重身份验证
身份和访问管理是安全之锚,是企业 IT 部门的首要任务.它是随时随地向员工.合作伙伴和客户提供访问的关键所在.今天,我们非常高兴地宣布正式发布 Windows Azure 多重身份验证,从而为 IT ...
- HDU 1870 愚人节的礼物
题解:简单的数括号问题…… #include <cstdio> char s[1005]; int main(){ while(scanf("%s",s)!=EOF){ ...
- hdoj 1824 Let's go home(2-SAT)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1824 思路分析:该问题为2-SAT问题:需要注意逻辑推理的等价性: (1)题目第一个条件:每一个队或者 ...
- 框架技术--Spring自动加载配置
今天项目中遇到一个问题,一个方法在服务启动后会自动被执行,查看了下配置未发现有定时的配置.但是后来发现是spring配置了启动时默认加载了方法. 代码: <?xml version=" ...
- Objective-c 方法的调用
在书写了类的声明和实现后,应用程序如何去调用它呢? 在Objective-c中,调用方法的简单格式如下: 1⃣ [实例 方法]; 如: [person setAge:32]; 其中 pe ...