uva 10719 - Quotient Polynomial
来源:互联网 发布:网站seo综合诊断 编辑:程序博客网 时间:2024/05/18 04:10
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
Special thanks to Tanveer Ahsan
q(i) = p(i) + k * p(i - 1)
r = q[n - 1]
输入的时候调了很久
#include <stdio.h>#define N 10010int p[N], q[N];int main(){int k;char temp;while (scanf("%d", &k) != EOF) {int n = 0;scanf("%d%c", &p[n++], &temp);while (temp != '\n'){scanf("%d%c", &p[n++], &temp);}q[0] = p[0];for (int i = 1; i < n; i++)q[i] = p[i] + k * q[i - 1];printf("q(x):");for (int i = 0; i < n - 1; ++i)printf(" %d", q[i]);printf("\nr = %d\n\n", q[n - 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
- bash手册翻译#3.1 shell语法
- 8-21 UINavigationController
- ZOJ 3778 Talented Chef
- 读书计划又启动了——代码大全2(1)
- C语言二叉树的数据结构实现
- uva 10719 - Quotient Polynomial
- C语言基础知识之(五):break 和 continue 运用详解
- java内存溢出示例(堆内存、栈内存)
- Nginx开发从入门到精通三
- 虚拟机搭建Hadoop集群(1) ---nat模式
- python中的urlencode与urldecode
- SQLmap
- 最大连续区间和问题 —— 转自purplest C++博客
- 黑马程序员------Java缓存—浅谈Memcached