题目链接:

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

Problem Description
You probably know those quizzes in Sunday magazines: given the sequence 1, 2, 3, 4, 5, what is the next number? Sometimes it is very easy to answer, sometimes it could be pretty hard. Because these "sequence problems" are very popular, ACM wants to implement them into the "Free Time" section of their new WAP portal. 
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

. If aD <> 0, the number D is called a degree of the polynomial. Note that constant function P(n) = C can be considered as polynomial of degree 0, and the zero function P(n) = 0 is usually defined to have degree -1.
 
Input
There is a single positive integer T on the first line of input. It stands for the number of test cases to follow. Each test case consists of two lines. First line of each test case contains two integer numbers S and C separated by a single space, 1 <= S < 100, 1 <= C < 100, (S+C) <= 100. The first number, S, stands for the length of the given sequence, the second number, C is the amount of numbers you are to find to complete the sequence.

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.

 
Output
For every test case, your program must print a single line containing C integer numbers, separated by a space. These numbers are the values completing the sequence according to the polynomial of the lowest possible degree. In other words, you are to print values Pmin(S+1), Pmin(S+2), .... Pmin(S+C).

It is guaranteed that the results Pmin(S+i) will be non-negative and will fit into the standard integer type.

 
Sample Input
4
6 3
1 2 3 4 5 6
8 2
1 2 4 7 11 16 22 29
10 2
1 1 1 1 1 1 1 1 1 2
1 10
3
 
Sample Output
7 8 9
37 46
11 56
3 3 3 3 3 3 3 3 3 3
 
题解:
 
参考别人写的,跑了下样例帮助理解>-<:http://blog.csdn.net/wangjie_wang/article/details/9149683
 
ac代码:
 #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 差分的更多相关文章

  1. HDOJ 1121 Complete the Sequence

    [题目大意]有一个数列P,它的第i项是当x=i时,一个关于x的整式的值.给出数列的前S项,你需要输出它的第S+1项到第S+C项,并且使整式的次数最低.多测. [数据范围]数据组数≤5000,S+C≤1 ...

  2. UVA 1546 - Complete the sequence!(差分法)

    UVA 1546 - Complete the sequence! 题目链接 题意:给定多项式前s项,求出后c项,要求尽量小 思路:利用差分法,对原序列求s - 1次差分,就能够发现规律,然后对于每多 ...

  3. HDU 5783 Divide the Sequence(数列划分)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  4. Complete the Sequence[HDU1121]

    Complete the Sequence Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  5. 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence

    // 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...

  6. 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区间上的所以数变成 ...

  7. Hdu 5496 Beauty of Sequence (组合数)

    题目链接: Hdu 5496 Beauty of Sequence 题目描述: 一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和.问:一个整数序列的所有子序列的完美序列和? 解题 ...

  8. Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)

    Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...

  9. HDU 5063 Operation the Sequence(暴力)

    HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...

随机推荐

  1. less的在线安装

    首先打开命令行窗口windonws+r输入cmd回车 1.确认是安装了node和less,在命令行输入“node -v”回车确认node是否安装,有版本信息则安装了,输入“lessc -v”回车确认l ...

  2. python3配置文件的增删改查,记录一下

    #!/usr/bin/env python3 import json #json模块,用于将像字典的字符串转换为字典 import re #re模块,查找替换 import shutil #copy文 ...

  3. python3 class类 练习题

    """一.定义一个学生Student类.有下面的类属性:1 姓名 name2 年龄 age3 成绩 score(语文,数学,英语) [每课成绩的类型为整数] 类方法:1 ...

  4. SSM(Spring5.x+Mybatis3)框架搭建【解决日志问题】(Github源码)

    闲来无事,用SSM写个小东西,发现spring已经迭代到5.x了,遂出此文,希望对各位同学有些许帮助. IDE:idea OS:windows 源代码:https://github.com/JHeav ...

  5. BFC与浮动

    一.BFC的含义 BFC(block formatting contexts) 块级元素格式化上下文,它决定了块级元素如何对它的内容进行布局,以及与其它元素的关系和相互作用. 块级元素:父级(是一个块 ...

  6. FPGA静态时序分析基础

    FPGA静态时序分析基础 基本概念 Skew: 时钟偏移 Skew表示时钟到达不同触发器的延时差别,Tskew = 时钟到达2号触发器的时刻 - 时钟到达1号触发器的时刻. Jitter: 时钟抖动 ...

  7. 阻止Quartus优化掉信号

    使用SignalTap II Logic Analyzer观察信号,有时要观察的信号会被Quartus优化掉,这种情况下可以给信号指定属性.以下例子均使用Verilog. 1. 如果是组合逻辑信号,可 ...

  8. Ubuntu配置android环境

    jdk:http://www.oracle.com/technetwork/cn/java/javase/downloads/index.html 安装JDK的步骤:http://jingyan.ba ...

  9. 【LG3236】[HNOI2014]画框

    [LG3236][HNOI2014]画框 题面 洛谷 题解 和这题一模一样. 将最小生成树换成\(KM\)即可. 关于复杂度,因为决策点肯定在凸包上,且\(n\)凸包的期望点数为\(\sqrt {\l ...

  10. Yii 2.0 使用验证码

    Yii2.0 提供了验证码组件.调用起来比较方便.以登录页面添加验证码为例. 1. 模型中添加字段和验证规则. common\models\LoginForm 添加如下代码 public $captc ...