C - 曼联
2015-08-01 14:06
281 查看
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 satisfies e[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 fraction a/b which satisfies thata 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.
题意:输入n,n组数,每组两个数,前者代表x的系数,后者代表x的幂数,求该函数
原函数x的系数和幂数。
Sample Input
3
1 0 3 2 2 4
Sample Output
1 1 1 3 2/5 5
Hint
f(x) = 1 + 3x2 + 2x4
After integrating we get: ∫f(x)dx = x + x3 + (2/5)x5
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 satisfies e[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 fraction a/b which satisfies thata 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.
题意:输入n,n组数,每组两个数,前者代表x的系数,后者代表x的幂数,求该函数
原函数x的系数和幂数。
Sample Input
3
1 0 3 2 2 4
Sample Output
1 1 1 3 2/5 5
Hint
f(x) = 1 + 3x2 + 2x4
After integrating we get: ∫f(x)dx = x + x3 + (2/5)x5
<span style="font-family:SimSun;font-size:18px;">#include <cstdio> #include <algorithm> #include <cmath> using namespace std; int n,key; struct node { int k,e; } st[1002]; int main() { while(~scanf("%d",&n)) { for(int i=1; i<=n; i++) { int cc; scanf("%d %d",&st[i].k,&cc); st[i].e=cc+1; } for(int i=1; i<=n; i++) { if(st[i].k%st[i].e==0) printf("%d %d%c",st[i].k/st[i].e,st[i].e,i==n?'\n':' '); else { int pp; if(st[i].k<0) //求两个数能同时整除的数时用两个数的正值求 pp=-st[i].k; else pp=st[i].k; key=__gcd(pp,st[i].e); printf("%d/%d %d%c",st[i].k/key,st[i].e/key,st[i].e,i==n?'\n':' '); } } } return 0; }</span>
相关文章推荐
- 跨域的请求数据
- 我的linux分区方案
- nutch 过滤字符
- HTML生成一个二维码,微信扫一扫,可以对网页分享
- PAT (Advanced Level) 1099. Build A Binary Search Tree (30) 中序遍历往BST中填数据
- LeetCode 14 Longest Common Prefix 0ms实现的算法
- HDU 4982/BC 6B Goffi and Squary Partition
- 有符号char的+、-法位运算过程
- 2015中国互联网金融影响力50人排行榜
- floyd + 记录路径 hdu 1385
- 【LeetCode 50】Pow(x, n)
- qt学习第一课:Hello Qt
- CSS 整理(2)
- Linux 下vi 命令大全
- C++ 输入输出总结
- eigen的基础配置 以及 cmake下cgal的demo&examples下的配置
- ural 1058 chocolate
- CNN
- python模块 - 常用模块推荐
- Leetcode #80 Remove Duplicates from Sorted Array II