1 条题解
-
0
第十八题:
题目描述:
2583:Series Determination
题目链接:
P2583——Series Determination——柒行(www.oj7.cn)
题目来源:
South Central USA 2003
总时间限制:
1000ms
内存限制:
65536kB
Boudreaux and Thibodeaux aren't very good at math, so they need you to write a program that can determine the second degree polynomial used to generate a given sequence of three integers. As proof that you've figured out the polynomial, they want your program to print out the next 3 integers in the sequence.
You know that each sequence is generated by a polynomial of the form f(x) = Ax2 + Bx + C, where A, B, and C are integers in the range (-103 <= (A, B, C) <= 103). You are given the values f(0), f(1), f(2) and are to determine the values f(3), f(4), f(5).
输入
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets.
Each data set consists of a single line containing the space-separated integer values of the polynomial evaluated at 0, 1, and 2 (in that order). These values will be in the range (-103 <= (f(0), f(1), f(2)) <= 103).
输出
For each data set, there will be exactly one line of output containing the space-separated integer values of the polynomial evaluated at 3, 4, and 5 (in that order). These values will be in the range (-104 <= (f(3), f(4), f(5)) <= 104).
样例输入
0 0 0 1 1 1 1 2 3 0 1 4 0 2 8
样例输出
0 0 0 1 1 1 4 5 6 9 16 25 18 32 50
中文题面:
描述 Boudreaux 和 Thibodeaux 在数学方面不太擅长,所以他们需要你编写一个程序来确定用于生成给定三个整数序列的二次多项式。作为证明你已经找出了该多项式,他们希望你的程序打印出序列中的下一个三个整数。 你知道每个序列都是由形式为 的多项式生成的,其中 A、B 和 C 是范围在 内的整数。你被给出了 的值,并需要确定 的值。 输入 这个问题的输入将包含最多 个数据集(非空)。每个数据集按照以下描述格式化,并且数据集中没有空白行分隔。 每个数据集由一行组成,包含以空格分隔的多项式在 0、1 和 2 处评估的整数值(按此顺序)。这些值的范围是 。 输出 对于每个数据集,将有且只有一行输出,包含以空格分隔的多项式在 处评估的整数值(按此顺序)。这些值的范围是 。
样例输入
0 0 0 1 1 1 1 2 3 0 1 4 0 2 8
样例输出
0 0 0 1 1 1 4 5 6 9 16 25 18 32 50
算法标签
差分方程
解题思路
输入读取:
读取三个整数 。
系数计算:
根据给定的公式计算出系数 。
递推计算:
利用计算出的系数 以及初始值 ,推导出后续的值 。
实现步骤
初始化变量并输入: 定义 ,使用 while 循环和 scanf 函数不断读取输入。
计算系数:
将 f0 赋值给 C。然后,通过公式 计算系数 计算系数 B。
推导后续值:
计算f3。计算f4。计算f5。
C++实现
#include <iostream> #include <stdio.h> using namespace std; int main(){ int f0,f1,f2; while(scanf("%d %d %d",&f0,&f1,&f2)==3){ int C=f0; int A=(f2+f0-2*f1)/2; int B=(f1-f0)-A; int f3=9*A+3*B+C; int f4=16*A+4*B+C; int f5=25*A+5*B+C; cout<<f3<<" "<<f4<<" "<<f5<<endl; } return 0; }
- 1
信息
- ID
- 1584
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 6
- 已通过
- 1
- 上传者