SDUT2015暑假集训14级周赛1 C - 曼联(积分+求最大公yue数)
来源:互联网 发布:淘宝刀剑神域99 编辑:程序博客网 时间:2024/04/30 05:15
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[n] e[n]
where k[i] and e[i] respectively represent the coefficients and exponents of nonzero terms, and satisfies e[1] < e[2] < ... < e[n].
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[n], e[n]。
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
31 0 3 2 2 4
Sample Output
1 1 1 3 2/5 5题目大意是给定一个多项式的系数和指数,求解它积分的系数和指数。//注意当系数/指数不为整数时,要用GCD求解最大公yue数(且两数求解最大公寓数应该全为正数)。#include<iostream>#include<cstring>#include<cstdio>using namespace std;struct node{ int c,e;} q[2015];int G(int a,int b)///{ int t; if(a<0) a=-a; if(b<0) b=-b; if(a<b) { t=a; a=b; b=t; } while(b!=0) { t=a%b; a=b; b=t; } return a;}int main(){ int n,m,i,j; ios::sync_with_stdio(false); while(cin>>n&&n) { for(i=0; i<n; i++) { cin>>q[i].c>>q[i].e; } for(i=0; i<n; i++) { if( q[i].c%(q[i].e+1)==0&&(q[i].e+1)!=0 ) { printf("%d ", q[i].c/(q[i].e+1) ); } else { int p=G(q[i].c,q[i].e+1); printf("%d/%d ",q[i].c/p,(q[i].e+1)/p); } if(i==n-1) { printf("%d",q[i].e+1); printf("\n"); } else printf("%d ",q[i].e+1); } } return 0;}
- SDUT2015暑假集训14级周赛1 C - 曼联(积分+求最大公yue数)
- SDUT2015暑假集训14级周赛1 B - 皇马(组合数)
- SDUT2015暑假集训14级周赛1 E - 尤文图斯(NP-博弈)
- SDUT2015暑假集训14级周赛4
- Codeforces Round #257 (Div. 2) 题解 SDUT2015暑假集训14级周赛3 C - 道
- Codeforces Round #254 (Div. 2) SDUT2015暑假集训14级周赛2 (并查集)
- 求两个数的最大公因子
- 求最大公因子
- 求最大公因子
- 求最大公因子算法
- CSU-ACM2017暑假集训比赛1 C
- CSU-ACM2017暑假集训比赛1 C
- CSU-ACM2017暑假集训比赛1 C
- 暑假集训第二周大一周六赛 C - 单词数
- 求两个数的最大公因子和最小公倍数的研究
- 辗转相除法------求 最大公因子
- 求最小公倍数以及最大公因子
- 求最大公因子-欧几里德算法
- 34款Firefox渗透测试插件
- android开发常用基础操作
- 编程之美:第三章 结构之法 3.6编程判断两个链表是否交叉
- Scala入门到精通——第十五节 Case Class与模式匹配(二)
- 8.属性和继承
- SDUT2015暑假集训14级周赛1 C - 曼联(积分+求最大公yue数)
- 计算满月的时间
- Bootstrap组件之well、标签
- python2.7下的windows安装virtualenv和flask
- Linux 命令行快捷键
- linux安装
- 寻找多数元素
- 编程之美:第三章 结构之法 3.7队列中取最大值操作问题
- ubuntu 安装phpmyadmin