周赛-Integration of Polynomial 分类: 比赛 2015-08-02 08:40 10人阅读 评论(0) 收藏
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) 收藏的更多相关文章
- Tautology 分类: POJ 2015-06-28 18:40 10人阅读 评论(0) 收藏
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10428 Accepted: 3959 Descri ...
- 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 ...
- 灰度世界算法(Gray World Algorithm) 分类: 图像处理 Matlab 2014-12-07 18:40 874人阅读 评论(0) 收藏
人的视觉系统具有颜色恒常性,能从变化的光照环境和成像条件下获取物体表面颜色的不变特性,但成像设备不具有这样的调节功能, 不同的光照环境会导致采集的图像颜色与真实颜色存在一定程度的偏差,需要选择合适的颜 ...
- 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 ...
- 第十二届浙江省大学生程序设计大赛-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 ...
- 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 ...
- 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 ...
- 第十二届浙江省大学生程序设计大赛-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 ...
- 山东理工大学第七届ACM校赛-飞花的线代 分类: 比赛 2015-06-26 10:29 10人阅读 评论(0) 收藏
飞花的线代 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 飞花壕的线代一直非常的壕(好),线代考试每次都是全班第一.一次,飞花壕在预习 ...
随机推荐
- leetcode23 多个拍好序的链表进行归并排序 (java版本)
题目: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexit ...
- 转:python webdriver API 之定位一组对象
webdriver 可以很方便的使用 find_element 方法来定位某个特定的对象,不过有时候我们却需要定位一组对象,WebElement 接口同样提供了定位一组元素的方法 find_eleme ...
- [转]Apache Maven 入门篇 ( 上 )
原文地址:Apache Maven 入门篇 ( 上 ) 作者:George Ma 写这个 maven 的入门篇是因为之前在一个开发者会的动手实验中发现挺多人对于 maven 不是那么了解,所以就有了这 ...
- 实现listview的条目点击后改变背景颜色
gv_categoryeffect_gridview.setChoiceMode(GridView.CHOICE_MODE_SINGLE);,再设置一个selector的背景选择器 getResour ...
- hue安装与部署
运行环境 centOS 6.6 hadoop 2.4.0 hive 1.2.0 spark 1.4.1 HUE 3.9 介绍: Hue是一个开源的Apache Hadoop UI系统,最早是由Clou ...
- WebForm中<%=%>与<%#%>的区别?
1<%=%>相当于Response.Write(),是输出变量的值 2<%#%>专门用于数据绑定,可以绑定一些变量或者数据源中的信息,中间绑定是数据源的条目,若想让它起作用,必 ...
- 封装cookie localStorage sessionStorage
var cookie = function(name, value, options) { if (typeof value !== 'undefined') { options = options ...
- 安装VirtalBox虚拟机的一些问题归纳
1.分别下载VirtalBox软件和镜像,进行安装出现一个问题:换了一个.dll动态库,用管理员权限运行修改BIOS 中Intel Virtual Technology Enabled!2.功能:虚拟 ...
- OpenStack 的NAT解决办法
原因 iptables中的nat表会对数据进行封包换目标,源地址,在我们的系统中是不需要的.所以我们做了如下操作 操作 /etc/nova/nova.conf的 1 2 #routing_source ...
- JavaScript复习笔记——字符串
String构造器可以使用new调用,也可以不使用,但是,这两种调用的结果也是完全不一样的.用new调用的时候,String作为构造器函数,创建字符串对象.不使用new的时候,String用作一个常规 ...