ZOJ2969
来源:互联网 发布:网络摄像机检测报告 编辑:程序博客网 时间:2024/06/07 16:09
Calculating the derivation of a polynomial is an easy task. Given a function f(x) , we use (f(x))' to denote its derivation. We use x^n to denote xn. To calculate the derivation of a polynomial, you should know 3 rules:
(1) (C)'=0 where C is a constant.
(2) (Cx^n)'=C*n*x^(n-1) where n>=1 and C is a constant.
(3) (f1(x)+f2(x))'=(f1(x))'+(f2(x))'.
It is easy to prove that the derivation a polynomial is also a polynomial.
Here comes the problem, given a polynomial f(x) with non-negative coefficients, can you write a program to calculate the derivation of it?
Input
Standard input will contain multiple test cases. The first line of the input is a single integerT (1 <= T <= 1000) which is the number of test cases. And it will be followed byT consecutive test cases.
There are exactly 2 lines in each test case. The first line of each test case is a single line containing an integerN (0 <= N <= 100). The second line contains N + 1 non-negative integers,CN, CN-1, ..., C1, C0, ( 0 <= Ci <= 1000), which are the coefficients of f(x).Ci is the coefficient of the term with degree i in f(x). (CN!=0)
Output
For each test case calculate the result polynomial g(x) also in a single line.
(1) If g(x) = 0 just output integer 0.otherwise
(2) suppose g(x)= Cmx^m+Cm-1x^(m-1)+...+C0 (Cm!=0),then output the integersCm,Cm-1,...C0.
(3) There is a single space between two integers but no spaces after the last integer.
Sample Input
301023 2 1310 0 1 2
Sample Output
06 230 0 1
题目就是让你求多项式的一次导数。
注意要对只有常数的多项式做特判断。
#include<bits/stdc++.h>#define clr(x) memset(x, 0, sizeof(x))#define LL long longusing namespace std;const int INF = 0x3f3f3f3f;const int maxn = 100005;int main(){ int T; cin >> T; while(T--) { int n; cin >> n; int a[105]; for(int i = n; i >= 0; i--) scanf("%d", &a[i]); if(n == 0) { puts("0"); continue; } for(int i = n; i >= 1; i--) printf("%d%c",a[i] * i, i == 1 ? '\n' : ' '); }}
- ZOJ2969
- zoj2969
- ZOJ2969
- ZOJ2969-Easy Task
- java文件操作之Path,Paths,Files
- 模型评估与选择-----第三部分
- 【java小白成长记】controller的一点心得
- (转)ListView BaseAdapter中的观察者模式
- jupyter报错"ImportError: No module named shutil_get_terminal_size"
- ZOJ2969
- Android 按钮的四种点击事件
- MSP430F149嵌入式系统中FLASH K9F1G08U0M的应用
- 逻辑门
- unit10 日志同步
- 阿里云服务器ssh经常一段时间就断掉解决办法
- Linux下的简单进度条实现
- jQuery的deferred对象详解
- StringBuffer和StringBuilder的区别