uva 10719(数学)
来源:互联网 发布:屏幕碎裂特效 js 编辑:程序博客网 时间:2024/06/05 07:01
题目:
A polynomial of degreen 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 andk = 3 then q(x) = x2 - 4x + 3 andr = 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
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
题解:递推公式,q[i] = a[i] + k * q[i - 1].
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 10005;int main() {int k, an[N], q[N], n, i;char c;while (scanf("%d", &k) != EOF) {n = 0;while (1) {scanf("%d%c", &an[n++], &c);if (c == '\n')break;}q[0] = an[0];for (i = 1; i < n; i++)q[i] = an[i] + k * q[i - 1];printf("q(x): ");for (i = 0; i < n - 2; i++)printf("%d ", q[i]);printf("%d\n", q[n - 2]);printf("r = %d\n\n", q[n - 1]);memset(an, 0, sizeof(an));memset(q, 0, sizeof(q));}return 0;}
- uva 10719(数学)
- UVa 10719 Quotient Polynomial (数学)
- uva 11427 数学-概率
- UVa 846 Steps (数学)
- uva 数学专题入门
- UVA 10025(数学)
- uva 11538 组合数学
- uva 11401 数学
- uva 113(数学)
- uva 10161(数学)
- uva 621(数学)
- uva 591(数学)
- uva 107(数学)
- uva 573(数学)
- uva 846(数学)
- uva 10499(数学)
- uva 305(数学)
- uva 10790(数学)
- js方法内Ajax请求数据判断,验证无效(OnClientClick="return Method();"),还是直接执行后台代码
- unity + win8.1 apps 小游戏demo
- 个人简单通信录
- POJ 1328 Radar Installation 贪心
- Android Wear - App Structure for Android Wear(应用结构)
- uva 10719(数学)
- Python 解析XML文件
- Cocos2d-x 3.1.1 学习日志8--2分钟让你了解cocos2d-x3.1.1 文本类
- python-ConfigParser
- info.plist的选项含义
- cocos2d-x-3.2启用Box2d物理引擎
- 2014-7-16-表单提交(回调)
- Repeater 换行显示
- STL 源码剖析 算法 stl_algobase.h