uva10719
来源:互联网 发布:徐州淘宝店铺装修 编辑:程序博客网 时间:2024/06/02 05:57
Problem B
Quotient Polynomial
Time Limit
2 Seconds
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.
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
1 scanf("%d%c");
cin吸收空格;
2 一开始感觉挺难不想做了仔细一看是个大水题;
#include<iostream>#include<cstdio>using namespace std;int main(){ int k,a[20000]; char ch=0; while(cin>>k) { getchar(); int i=0; while(scanf("%d%c",&a[i++],&ch)) if(ch=='\n') break; int n=i-1; for(i=0;i<(n+1)/2;i++) { int temp=a[i]; a[i]=a[n-i]; a[n-i]=temp; } int b[20000]; b[n-1]=a[n]; for(i=n-2;i>=0;i--) b[i]=a[i+1]+k*b[i+1]; int r=a[0]+b[0]*k; cout<<"q(x):"; for(i=n-1;i>=0;i--) cout<<' '<<b[i]; cout<<endl; cout<<"r = "<<r<<endl; cout<<endl; } return 0;}
0 0
- uva10719
- uva10719(数学)
- UVA10719- Quotient Polynomial
- UVA10719 Quotient Polynomial
- UVA10719-多项式除法的商
- 我的改进版2048(1)
- windows7下的eclipse运行Mapreduce程序的配置
- 集合总结
- C12_OC02-OC较C的不同
- 如何学习的进步的速度最快了?
- uva10719
- C13_OC03-面向对象
- 【Qt】Qpainter制作二维图
- C++中int型与string型互相转换
- [学习中的错误记录]
- C++动态申请数组和参数传递问题
- LeetCode Sqrt(x)
- VS2005的配置问题-mainifest 查看所需依赖项
- Codeforces 425B