UVa 10719 Quotient Polynomial
2013-11-06 19:33
447 查看
A polynomial of degree n can be expressed as
If k is any integer then we can write:
Here q(x) is called the quotient polynomial of p(x) of degree (n-1) and r is any integer which is called the remainder.
For example, if p(x) = x3 - 7x2+ 15x - 8 and k = 3 then q(x) = x2 - 4x + 3 and r = 1. Again if p(x) = x3 - 7x2+ 15x - 9 and k
= 3 then q(x) = x2 - 4x + 3 and r = 0.
In this problem you have to find the quotient polynomial q(x) and the remainder r. All the input and output data will fit in 32-bit signed integer.
Input
Your program should accept an even number of lines of text. Each pair of line will represent one test case. The first line will contain an integer value for k. The second line will contain a list of integers (an,
an-1, … a0), which represent the set of co-efficient of a polynomial p(x). Here 1 ≤ n ≤ 10000. Input is terminated by <EOF>.
Output
For each pair of lines, your program should print exactly two lines. The first line should contain the coefficients of the quotient polynomial. Print the reminder in second line. There is a blank space before and after the ‘=’ sign. Print a
blank line after the output of each test case. For exact format, follow the given sample.
题目并不难,一次A过,主要是推出相应关系即可。
代码如下:
[align=left][/align]
If k is any integer then we can write:
Here q(x) is called the quotient polynomial of p(x) of degree (n-1) and r is any integer which is called the remainder.
For example, if p(x) = x3 - 7x2+ 15x - 8 and k = 3 then q(x) = x2 - 4x + 3 and r = 1. Again if p(x) = x3 - 7x2+ 15x - 9 and k
= 3 then q(x) = x2 - 4x + 3 and r = 0.
In this problem you have to find the quotient polynomial q(x) and the remainder r. All the input and output data will fit in 32-bit signed integer.
Input
Your program should accept an even number of lines of text. Each pair of line will represent one test case. The first line will contain an integer value for k. The second line will contain a list of integers (an,
an-1, … a0), which represent the set of co-efficient of a polynomial p(x). Here 1 ≤ n ≤ 10000. Input is terminated by <EOF>.
Output
For each pair of lines, your program should print exactly two lines. The first line should contain the coefficients of the quotient polynomial. Print the reminder in second line. There is a blank space before and after the ‘=’ sign. Print a
blank line after the output of each test case. For exact format, follow the given sample.
Sample Input | Output for Sample Input |
3 1 –7 15 –8 3 1 –7 15 –9 | q(x): 1 -4 3 r = 1 q(x): 1 -4 3 r = 0 |
代码如下:
#include <stdio.h> int main(void) { int k,i,j; int a[10001],b[10001]; while(scanf("%d",&k)!=EOF) { getchar(); scanf("%d",&a[0]); for(i=1;getchar()!='\n';i++) scanf("%d",&a[i]); printf("q(x): %d",a[0]); b[0]=a[0]; for(j=1;j<i-1;j++) { b[j]=a[j]+k*b[j-1]; printf(" %d",b[j]); } printf("\nr = %d\n\n",a[j]+k*b[j-1]); } return 0; }
[align=left][/align]
相关文章推荐
- chmod命令详细用法
- windows下搭建cakephp+bootstrap环境
- linux shell 中 " if [ ]; ... then ... fi " 的使用
- 黑马程序员——集合&List
- 有关The Last Promise的汉化②改写程序
- 南阳理工OJ_1的个数
- SCOM2012功能测试(1)—发现计算机并安装客户端
- 通过淘宝IP地址库获取IP位置
- HDU2578--Dating with girls(1) (map||排序+二分)
- feeling
- android每次调试程序 模拟器都重新启动 非常不爽
- memcached搭建和使用要点
- memcached搭建和使用要点
- su与su-切换用户
- 打开chm乱码时解决方案
- 面试经历(华为,瑞晟,大华,海康,虹软,顺丰)
- Grade 的分佈
- Python里安装NumPy模块
- 装修开工
- 旧系统改造--电子值班系统