Integration of Polynomial (周赛1)
2015-08-08 17:20
393 查看
Description
Suppose there are a polynomial which has n nonzero terms, please print the integration polynomial of the given polynomial.
The polynomial will be given in the following way, and you should print the result in the same way:
k[1] e[1] k[2] e[2] ... k
e
where k[i] and e[i] respectively represent the coefficients and exponents of nonzero terms, and satisfiese[1] < e[2] < ... < e
.
Note:
Suppose that the constant term of the integration polynomial is 0.
If one coefficient of the integration polynomial is an integer, print it directly.
If one coefficient of the integration polynomial is not an integer, please print it by using fractiona/b which satisfies that
a is coprime to b.
Input
There are multiple cases.
For each case, the first line contains one integer n, representing the number of nonzero terms.
The second line contains 2*n integers, representing k[1], e[1], k[2], e[2], ..., k
, e
。
1 ≤ n ≤ 1000
-1000 ≤ k[i] ≤ 1000, k[i] != 0, 1 ≤ i ≤ n
0 ≤ e[i] ≤ 1000, 1 ≤ i ≤ n
Output
Print the integration polynomial in one line with the same format as the input.
Notice that no extra space is allowed at the end of each line.
Sample Input
Sample Output
定积分
= =
Suppose there are a polynomial which has n nonzero terms, please print the integration polynomial of the given polynomial.
The polynomial will be given in the following way, and you should print the result in the same way:
k[1] e[1] k[2] e[2] ... k
e
where k[i] and e[i] respectively represent the coefficients and exponents of nonzero terms, and satisfiese[1] < e[2] < ... < e
.
Note:
Suppose that the constant term of the integration polynomial is 0.
If one coefficient of the integration polynomial is an integer, print it directly.
If one coefficient of the integration polynomial is not an integer, please print it by using fractiona/b which satisfies that
a is coprime to b.
Input
There are multiple cases.
For each case, the first line contains one integer n, representing the number of nonzero terms.
The second line contains 2*n integers, representing k[1], e[1], k[2], e[2], ..., k
, e
。
1 ≤ n ≤ 1000
-1000 ≤ k[i] ≤ 1000, k[i] != 0, 1 ≤ i ≤ n
0 ≤ e[i] ≤ 1000, 1 ≤ i ≤ n
Output
Print the integration polynomial in one line with the same format as the input.
Notice that no extra space is allowed at the end of each line.
Sample Input
3 1 0 3 2 2 4
Sample Output
1 1 1 3 2/5 5
定积分
= =
#include <stdio.h> #include <math.h> int GY(int x,int y) { int t,r; if(x<y) { t=x;x=y;y=t; } while(y!=0) {r=x%y;x=y;y=r;} return x; } int main() { int n,x; int k[2000],e[2000]; while(~scanf("%d",&n)) { int i; int key; for(i=0;i<n;i++) { scanf("%d %d",&k[i],&e[i]); e[i]=e[i]+1; } for(i=0;i<n;i++) { if(i<n-1) { if(k[i]<0) { x=-1*k[i]; if(x%e[i]==0) printf("%d %d ",k[i]/e[i],e[i]); else { key=GY(x,e[i]); printf("%d/%d %d ",k[i]/key,e[i]/key,e[i]); } } else { x=k[i]; if(x%e[i]==0) printf("%d %d ",k[i]/e[i],e[i]); else { key=GY(x,e[i]); printf("%d/%d %d ",k[i]/key,e[i]/key,e[i]); } } } else { if(k[i]<0) { x=-1*k[i]; if(x%e[i]==0) printf("%d %d\n",k[i]/e[i],e[i]); else { key=GY(x,e[i]); printf("%d/%d %d\n",k[i]/key,e[i]/key,e[i]); } } else { x=k[i]; if(x%e[i]==0) printf("%d %d\n",k[i]/e[i],e[i]); else { key=GY(x,e[i]); printf("%d/%d %d\n",k[i]/key,e[i]/key,e[i]); } } } } } return 0; }
相关文章推荐
- hpuoj 1690 组合数【DFS】
- 大数阶乘
- matlab画神经网络的结构 neural network
- POJ C程序设计进阶 编程题#1:计算矩阵边缘之和
- lua lpeg
- zoj3644
- 矩阵的四次方
- MYSQL中的my.cnf中文说明
- A Mathematical Curiosity 水
- Java串口通信 ----> 扫描标签获取数据存入数据库
- 微信服务号如何认证
- 杭电1711Number Sequence
- 如何创建Oracle数据库
- 杨辉三角打印
- const常量与#define宏
- HDU The Number Off of FFF (周赛1)
- POJ 1816 Wild Words(字典树+dfs)
- 一道签到题
- 明明的随机数
- leetcode--WildcardMatching