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. c++怎么将一个类,拆分出接口类,和实现类

    还拿上一遍中定义的GradeBook类来实现: #include <iostream> using std::cout; using std::endl; #include <str ...

  2. Java内存分配全面浅析

    本文将由浅入深详细介绍Java内存分配的原理,以帮助新手更轻松的学习Java.这类文章网上有很多,但大多比较零碎.本文从认知过程角度出发,将带给读者一个系统的介绍. 进入正题前首先要知道的是Java程 ...

  3. 设置UISegmentedControl中字体大小

    [segmentedControl setTitleTextAttributes:@{NSFontAttributeName : DYBoldFont(20)}  forState:UIControl ...

  4. Appium的理念

    1.Appium的架构:C/S模式 Appium的核心是暴漏REST API的WebServer,appium接收来自客户端的连接请求,监听由客户端发起的命令,在移动设备上执行这些命令,这些命令的执行 ...

  5. 父类构造函数中的this指针在子类构造对象后,这个this指针指向什么

    子类的对象内存布局包括两部分:父类和子类派生部分,所以执行父类的构造函数只不过是在构造子类对象的父类部分.因此子类对象的this指针是指向子类对象自己.

  6. linux kernel.shmall shemax shemin 參數解釋

    分类: oracle linux 2010-06-17 14:30 6193人阅读 评论(0) 收藏 举报 linuxoracleredhat数据库服务器x86 Linux X86-64操作系统,Or ...

  7. mybatis的xml中特殊转义字符和模糊查询like的写法

    做个备忘: xml特殊符号转义写法 <          < >          > <>   <> &      & &ap ...

  8. 夺命雷公狗ThinkPHP项目之----企业网站18之网站配置列表页的完成

    我们点击下配置列表即可查看我们列表页的配置信息了: 其实这个最简单了,首先我们先来完成他控制器的代码: public function lists(){ $mod = M('Conf')->se ...

  9. [slim] Slim - Faster, lightweight, a enginer for Ruby

    URL: http://slim-lang.com/ Example: doctype html html head title Slim Examples meta name="keywo ...

  10. html规范整体结构

    <!DOCTYPE html><html lang="zh"><head> <meta charset="utf-8" ...