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 ...
随机推荐
- sign
sign字段构成:登录类型(2Bytes) + userid(不定长,最长10Bytes,用户id或设备id) + time(10Bytes) + token(32Bytes).其中:token = ...
- Idea项目中常见错误及笔记(Old)
1.Idea基础设置: File-->settings--> 1>修改字体:Font 2>修改编码格式:File Encodings(全部UTF-8,右下方复选框勾中--防止程 ...
- react-navigation的超级大坑
本文针对react-navigation^3.0.0版本,版本不对的话,请不要看本文,直接看官方英文文档 最近一直在学习RN,没找到什么好的视频,所以一直看文档,一路上来虽然遇到一些乱七八糟的bu ...
- 将Vue插件发布到npm的完整记录
前言 面对越来越多的组件库,越开越多的ui库,学会发布库已经是前端必须会的事情了,也算是为开源贡献一份力量,在网络上看了一些前者的文章,也算的发布成功了,虽然还存在很多问题,路不积跬步,无以至千里 ...
- Git最常用的命令 总结
stage/unstage git add xxx.xx 和 git reset HEAD xxx.xx 前者将本地的修改提交到index(此操作成为stage,参考备注1),后者将已提交到inde ...
- Linux入门第一天——基本概述与环境搭建
一.Linux简介 1.历史 Linux内核最初只是由芬兰人李纳斯·托瓦兹(Linus Torvalds)在赫尔辛基大学上学时出于个人爱好而编写的. Linux是一套免费使用和自由传播的类Unix操 ...
- 2016-2017-2 20155329 实验四 Android 开发
2016-2017-2 20155329 实验四 Android 开发 ## 任务一:Android Stuidio的安装测试: 参考<Java和Android开发学习指南(第二版)(EPUBI ...
- 1009 产生数 2002年NOIP全国联赛普及组
1009 产生数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给出一个整数 n(n< ...
- 在azure windows虚拟机上安装iis
在 dashboard-添加角色和功能-一直往下点就好了,后”选择安装类型“页面 中选择[基于角色或基于功能的安装],安装完成后 在浏览器输入 http://localhost/ 就可以正常访问网站了 ...
- 如何在存储过程的IN操作中传递字符串变量
原始SQL如下: SELECT MONTH(OrderTime) AS datetype, SUM(DeliveryCount) AS decount, Region FROM (SELECT dbo ...