Integration of Polynomial

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Submit Statistic Next Problem

Problem 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 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[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

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

数学的不定积分加GCD

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <list>
#include <algorithm>
#define LL long long
#define RR freopen("output.txt","r",stdoin)
#define WW freopen("input.txt","w",stdout) using namespace std; const int MAX = 100100; const int MOD = 1000000007; int k[1100],e[1100]; int num[1100];
int GCD(int a,int b)
{
return b==0?a:GCD(b,a%b);
}
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(num,0,sizeof(num));
for(int i=0;i<n;i++)
{
scanf("%d %d",&k[i],&e[i]);
e[i]++;
if(k[i]%e[i]==0)
{
k[i]/=e[i];
}
else
{
num[i]=e[i];
int ans=GCD(abs(k[i]),num[i]);
k[i]/=ans;
num[i]/=ans;
}
}
for(int i=0;i<n;i++)
{
if(i)
{
printf(" ");
}
if(num[i])
{
printf("%d/%d %d",k[i],num[i],e[i]);
}
else
{
printf("%d %d",k[i],e[i]);
}
}
printf("\n");
} return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

周赛-Integration of Polynomial 分类: 比赛 2015-08-02 08:40 10人阅读 评论(0) 收藏的更多相关文章

  1. Tautology 分类: POJ 2015-06-28 18:40 10人阅读 评论(0) 收藏

    Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10428   Accepted: 3959 Descri ...

  2. Monthly Expense(二分) 分类: 二分查找 2015-06-06 00:31 10人阅读 评论(0) 收藏

    Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...

  3. 灰度世界算法(Gray World Algorithm) 分类: 图像处理 Matlab 2014-12-07 18:40 874人阅读 评论(0) 收藏

    人的视觉系统具有颜色恒常性,能从变化的光照环境和成像条件下获取物体表面颜色的不变特性,但成像设备不具有这样的调节功能, 不同的光照环境会导致采集的图像颜色与真实颜色存在一定程度的偏差,需要选择合适的颜 ...

  4. Hiking 分类: 比赛 HDU 函数 2015-08-09 21:24 3人阅读 评论(0) 收藏

    Hiking Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...

  5. 第十二届浙江省大学生程序设计大赛-May Day Holiday 分类: 比赛 2015-06-26 14:33 10人阅读 评论(0) 收藏

    May Day Holiday Time Limit: 2 Seconds Memory Limit: 65536 KB As a university advocating self-learnin ...

  6. Task schedule 分类: 比赛 HDU 查找 2015-08-08 16:00 2人阅读 评论(0) 收藏

    Task schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. LightOJ1002 分类: 比赛 最短路 2015-08-08 15:57 15人阅读 评论(0) 收藏

    I am going to my home. There are many cities and many bi-directional roads between them. The cities ...

  8. 第十二届浙江省大学生程序设计大赛-Capture the Flag 分类: 比赛 2015-06-26 14:35 10人阅读 评论(0) 收藏

    Capture the Flag Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge In computer security, Ca ...

  9. 山东理工大学第七届ACM校赛-飞花的线代 分类: 比赛 2015-06-26 10:29 10人阅读 评论(0) 收藏

    飞花的线代 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 飞花壕的线代一直非常的壕(好),线代考试每次都是全班第一.一次,飞花壕在预习 ...

随机推荐

  1. JAVA类加载机制详解

    “代码编译的结果从本地机器码转变为字节码,是存储格式发展的一小步,却是变成语言发展的一大步”,这句话出自<深入理解JAVA虚拟机>一书,后面关于jvm的系列文章主要都是参考这本书. JAV ...

  2. javaapi中的排序

    有的时候需要对数组里的element进行排序.当然可以自己编写合适的排序方法,但既然java包里有自带的Arrays.sort排序方法,在 数组元素比较少的时候为何不用? Sorting an Arr ...

  3. hdu4918 Query on the subtree

    树分治,设当前树的分治中心为x,其子树分治中心为y,则设father[y]=x,分治下去则可以得到一颗重心树,而且树的深度是logn. 询问操作(x,d),只需要查询重心树上x到重心树根节点上的节点的 ...

  4. 解决maven编译spark1.5报错问题

    spark1.5发布了,赶紧去下了源码尝鲜 git clone git://github.com/apache/spark.git -b branch-1.5 输入命令进行编译 ./make-dist ...

  5. 同时启动多个Tomcat

    一,修改配置文件server.xml的端口 C:\apache-tomcat-5.5.23-1\conf\server.xml用记事本什么的打开修改3个地方   第一: <Server port ...

  6. requireJs和r.js压缩工具

    上面release是执行命令 node r.js -o build.js 生成的,需要切换到目录require/tools下面,也就是 有r.js和build.js的目录,才能执行命令 代码目录如上: ...

  7. 2.js基础

    4.函数 1)函数是一段完成“指定功能”的已经“命名”的代码段 2)函数只有“调用”才能使用到,调用就是通过名称(可以在声明之前,也可以在声明之后) 3)函数名.参数.函数体.返回值(没有返回值的函数 ...

  8. 为什么在我眼里你是一只傻逼——傻逼“常所用”句型之(2)——“当当网的就有XXX人评论,YYY%的推荐”

    A:这东西里面尽是大粪. B:这东西当当网的就有325人评论,98.8%的推荐.京东的整体评论是五星,37人评价,31人给好评,1人差评,5人中评:亚马逊有6条好评,1条中评. http://news ...

  9. 【NOIP模拟赛】秦时明月

    秦时明月 (sword.cpp/c/pas) [问题描述]   卫庄与盖聂又要论剑了,因为渊虹和鲨齿都是天下名剑,论剑容易互相损伤,太过可惜,于是两位换了两把木剑.因为木剑质地不匀,剑的每一段都有一个 ...

  10. js数组基础知识链接

    http://www.cnblogs.com/qiantuwuliang/archive/2011/01/08/1930499.html 小案例:   <script language=&quo ...