HDU 1121 Complete the Sequence 差分
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1121
Complete the Sequence
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 451 Accepted Submission(s): 283
ACM programmers have noticed that some of the quizzes can be solved by describing the sequence by polynomials. For example, the sequence 1, 2, 3, 4, 5 can be easily understood as a trivial polynomial. The next number is 6. But even more complex sequences, like 1, 2, 4, 7, 11, can be described by a polynomial. In this case, 1/2.n^2-1/2.n+1 can be used. Note that even if the members of the sequence are integers, polynomial coefficients may be any real numbers.
Polynomial is an expression in the following form:
P(n) = aD.n^D+aD-1.n^D-1+...+a1.n+a0
The second line of each test case contains S integer numbers X1, X2, ... XS separated by a space. These numbers form the given sequence. The sequence can always be described by a polynomial P(n) such that for every i, Xi = P(i). Among these polynomials, we can find the polynomial Pmin with the lowest possible degree. This polynomial should be used for completing the sequence.
It is guaranteed that the results Pmin(S+i) will be non-negative and will fit into the standard integer type.

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int maxn = ; int s, c;
int f[maxn][maxn]; void init() {
memset(f, , sizeof(f));
} int main() {
int tc;
scanf("%d", &tc);
while (tc--) {
init();
scanf("%d%d", &s, &c);
for (int i = ; i < s; i++) scanf("%d", &f[][i]);
for (int i = ; i <= s - ; i++) {
for (int j = ; j < s - i; j++) {
f[i][j] = f[i - ][j + ] - f[i - ][j];
}
}
for (int i = ; i <= c; i++) f[s - ][i] = f[s - ][i - ];
for (int i = s - ; i >= ; i--) {
for (int j = s - i; j < s + c - i; j++) {
f[i][j] = f[i][j - ] + f[i + ][j - ];
}
}
printf("%d", f[][s]);
for (int i = s + ; i < s + c; i++) printf(" %d", f[][i]);
printf("\n");
}
return ;
}
HDU 1121 Complete the Sequence 差分的更多相关文章
- HDOJ 1121 Complete the Sequence
[题目大意]有一个数列P,它的第i项是当x=i时,一个关于x的整式的值.给出数列的前S项,你需要输出它的第S+1项到第S+C项,并且使整式的次数最低.多测. [数据范围]数据组数≤5000,S+C≤1 ...
- UVA 1546 - Complete the sequence!(差分法)
UVA 1546 - Complete the sequence! 题目链接 题意:给定多项式前s项,求出后c项,要求尽量小 思路:利用差分法,对原序列求s - 1次差分,就能够发现规律,然后对于每多 ...
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- Complete the Sequence[HDU1121]
Complete the Sequence Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
- hdu 4893 Wow! Such Sequence!(线段树)
题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...
- Hdu 5496 Beauty of Sequence (组合数)
题目链接: Hdu 5496 Beauty of Sequence 题目描述: 一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和.问:一个整数序列的所有子序列的完美序列和? 解题 ...
- Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)
Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...
- HDU 5063 Operation the Sequence(暴力)
HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...
随机推荐
- django 登录注册注销
一.设计数据模型 1.数据库模型设计 作为一个用户登录和注册项目,需要保存的都是各种用户的相关信息.很显然,我们至少需要一张用户表User,在用户表里需要保存下面的信息: 用户名 密码 邮箱地址 性别 ...
- .NET Core On Liunx环境搭建之MongoDB
伴随着.NET Core的开源,Liunx服务器才是.NET 的未来,公司前几天刚刚上新了一台Liunx服务器,我进行了一下环境的搭建,把经验分享出来. 服务器信息: 服务器用的是阿里云服务器,操作 ...
- Redis全方位详解--磁盘持久化和容灾备份
序言 在上一篇博客中,博客介绍了redis的数据类型使用场景和redis分布式锁的正确姿势.我们知道一旦Redis重启,存在redis里面的数据就会全部丢失.所以这篇博客中向大家介绍Redis的磁盘持 ...
- laravel5.5源码笔记(五、Pipeline管道模式)
Pipeline管道模式,也有人叫它装饰模式.应该说管道是装饰模式的一个变种,虽然思想都是一样的,但这个是闭包的版本,实现方式与传统装饰模式也不太一样.在laravel的源码中算是一个比较核心的设计模 ...
- centos6.8安装mysql过程
1.验证Centos是否安装MySQL $>yum list installed | grep mysql 2.删除MySql $>yum –y remove mysql-libs.X86 ...
- x01.SportWeb: An Example for AspNetCore 2.0
新的刚来到,旧的就忘掉.学习 AspNet Core 2.0,没有好的例子,是很痛苦的.<Pro ASP.NET Core MVC 2>中的 SportsStore值得一看,不妨下载研究一 ...
- 111. Climbing Stairs 【LintCode easy】
Description You are climbing a stair case. It takes n steps to reach to the top. Each time you can e ...
- PL/SQL轻量版(三)——游标与异常处理
一.游标 1.概念 游标是一个 指向上下文的句柄( handle) 或指针.通过游标,PL/SQL 可以控制上下文区和处理语句时上下文区会发生些什么事情. 2.游标处理 处理显式游标 主要包含以下四个 ...
- cygwin环境搭建
可以在家目录下查看.bash_profile里的PATH.如果是:PATH=$PATH:$HOME/bin则需要添加成如下: PATH=$PATH:$HOME/bin:/sbin:/usr/bin:/ ...
- 20155223 2016-2017-2 《Java程序设计》第10周学习总结
20155223 2016-2017-2 <Java程序设计>第10周学习总结 教材学习内容总结 Java Socket编程 网络上的两个程序通过一个双向的通讯连接实现数据的交换,这个双向 ...