uva 10719 Quotient Polynomial
来源:互联网 发布:苹果电脑mac怎么下游戏 编辑:程序博客网 时间:2024/05/18 07:48
uva 10719 Quotient Polynomial
Description
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 ofp(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 thenq(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 polynomialq(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 fork. The second line will contain a list of integers (an, an-1, …a0), which represent the set of co-efficient of a polynomialp(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
题目大意:多项式求除法商,就是将多项式分解成p(x) = (x - k) * q(x), 求q(x)各项的系数.
解题思路:q(x)中除了最高次项的系数与p(x)最高项的系数相同,其它系数有一个规律q[i] = p[i] + k * q[i - 1].
PS:注意数组大小……
#include<stdio.h>#include<string.h>int main() {int p[10005], q[10005], k, cnt;char ch;while (scanf("%d", &k) != EOF) {cnt = 0;ch = '\0';memset(p, 0, sizeof(p));memset(q, 0, sizeof(q));while (1) {scanf("%d%c", &p[cnt++], &ch); if (ch == '\n') { break; }} q[0] = p[0];for (int i = 1; i < cnt; i++) { q[i] = p[i] + k * q[i - 1];}printf("q(x):");for (int i = 0; i < cnt - 1; i++) {printf(" %d", q[i]);}printf("\nr = %d\n\n", q[cnt - 1]);}return 0;}
- uva 10719 Quotient Polynomial
- uva 10719 - Quotient Polynomial
- UVa 10719 - Quotient Polynomial
- Uva 10719 - Quotient Polynomial
- UVa 10719 - Quotient Polynomial
- UVA 10719 Quotient Polynomial
- uva 10719 Quotient Polynomial
- UVa 10719 Quotient Polynomial
- UVa 10719 - Quotient Polynomial
- UVa 10719 - Quotient Polynomial
- UVA - 10719 Quotient Polynomial
- UVA - 10719 Quotient Polynomial
- uva 10719 Quotient Polynomial
- UVA - 10719 Quotient Polynomial
- uva 10719 Quotient Polynomial
- uva 10719 - Quotient Polynomial
- UVA - 10719 Quotient Polynomial
- UVA 10719-Quotient Polynomial
- 抽象工厂模式
- Nginx反向代理+DNS轮询+IIS7.5 千万PV 百万IP 双线 网站架构案例
- Xml:MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence.
- CodeForces 494A Treasure
- Android面试-如何动态改变RelativeLayout中的按钮布局
- uva 10719 Quotient Polynomial
- ANDROID开发之SQLite详解
- DB2 DBA技能要求
- HDU - 2817 - A sequence of numbers (快速幂取模!)
- 树-堆结构练习——合并果子之哈夫曼树
- 第十六周 Problem C:相同的数字
- Word Search
- ubuntu常用命令大全
- php实现文件下载和多文件上传