UVA10719 Quotient Polynomial多项式
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10719 Quotient Polynomial多项式相关的知识,希望对你有一定的参考价值。
A polynomial of degree n can be expressed as
p
(
x
)
=
a
n
x
n
+
a
n
−
1
x
n
−
1
+
⋅
⋅
⋅
+
a
1
x
+
a
0
p(x) = a_nx^n + a_{n−1}x^{n−1} + · · · + a_1x + a_0
p(x)=anxn+an−1xn−1+⋅⋅⋅+a1x+a0
If k is any integer then we can write:
p
(
x
)
=
(
x
−
k
)
q
(
x
)
+
r
p(x) = (x − k)q(x) + r
p(x)=(x−k)q(x)+r
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
)
=
x
3
−
7
x
2
+
15
x
−
8
p(x) = x^3 − 7x^2 + 15x − 8
p(x)=x3−7x2+15x−8 and k = 3 then
q
(
x
)
=
x
2
−
4
x
+
3
q(x) = x^2 − 4x + 3
q(x)=x2−4x+3 and r = 1. Again if
p
(
x
)
=
x
3
−
7
x
2
+
15
x
−
9
p(x) = x^3 − 7x^2 + 15x − 9
p(x)=x3−7x2+15x−9 and k = 3 then
q
(
x
)
=
x
2
−
4
x
+
3
q(x) = x^2 − 4x + 3
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 (
a
n
,
a
n
−
1
,
.
.
.
,
a
0
a_n, a_{n−1}, . . . , a_0
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
3
1 -7 15 -8
3
1 -7 15 -9
Sample Output
q(x): 1 -4 3
r = 1
q(x): 1 -4 3
r = 0
问题链接:UVA10719 Quotient Polynomial
问题简述:(略)
问题分析:多项式系数计算问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA10719 Quotient Polynomial */
#include <bits/stdc++.h>
using namespace std;
const int N = 10000 + 1;
int a[N], b[N];
int main()
{
int n;
while (scanf("%d", &n) == 1) {
char c;
int cnt = 0;
do {
scanf("%d", &a[cnt++]);
} while ((c = getchar()) != '\\n');
b[1] = a[0];
for (int i = 2; i <= cnt; i++)
b[i] = a[i - 1] + n * b[i - 1];
printf("q(x): ");
for (int i = 1; i < cnt - 1; i++)
printf("%d ", b[i]);
printf("%d\\n", b[cnt - 1]);
printf("r = %d\\n\\n", a[cnt - 1] + n * b[cnt - 1]);
}
return 0;
}
以上是关于UVA10719 Quotient Polynomial多项式的主要内容,如果未能解决你的问题,请参考以下文章
The 60th Spark Club Meeting: Emotional Quotient