题目链接:

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. php 计算两个日期相差天数

    <?php $startdate=strtotime("2013-3-09"); $enddate=strtotime("2013-4-05"); $da ...

  2. 基于visual studio 2017 以及cubemx 搭建stm32的开发环境(2)

    主要解决 vs2017中,printf无法打印数据的问题. 在keil环境下正常使用printf功能,但是以下的重定向代码在vs2017下使用不了: #ifdef __GNUC__ /* With G ...

  3. springcloud 笔记-服务注册中心

    1.搭建springcloud服务注册中心需要添加eureka的依赖: <?xml version="1.0" encoding="UTF-8"?> ...

  4. JVM内存模型(转载)

    原文地址:http://blog.csdn.net/u012152619/article/details/46968883 JVM定义了若干个程序执行期间使用的数据区域.这个区域里的一些数据在JVM启 ...

  5. 20155232 2016-2017-2《Java程序设计》课程总结

    20155232 2016-2017-2<Java程序设计>课程总结 作业汇总 (按顺序)每周作业链接汇总 预备作业1:你期望的师生关系是什么? 预备作业2:技能与经验之谈 预备作业3:初 ...

  6. 20155301 《Java程序设计》实验五网络编程与安全

    20155301 <Java程序设计>实验五网络编程与安全 实验内容 实验1: 两人一组结对编程:参考http://www.cnblogs.com/rocedu/p/6766748.htm ...

  7. 20155320 实验四 Android程序设计

    20155320 实验四 Android程序设计 实验内容 (一)Android Stuidio的安装测试: 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java for ...

  8. 20155332 2006-2007-2 《Java程序设计》第3周学习总结

    学号 2006-2007-2 <Java程序设计>第3周学习总结 教材学习内容总结 尽量简单的总结一下本周学习内容 尽量不要抄书,浪费时间 看懂就过,看不懂,学习有心得的记一下 教材学习中 ...

  9. 【MongoDB】NoSQL Manager for MongoDB 教程(基础篇)

    前段时间,学习了一下mongodb,在客户端工具方面,个人认为 NoSQL Manager for MongoDB 是体验比较好的一个,功能也较齐全.可惜在找教程的时候,发现很难找到比较详细的教程,也 ...

  10. 【SAP BI】BW如何连接SQLSERVER数据库

    一.工具 源版本: SQLSERVER2008  数据库TEST 目标版本:  SAP 客户端 7.4  服务器7.5 二.在BW中建立数据库连接,并生成数据源 2.1  登录SAP BW开发机 ,输 ...