Limit
2016-02-26 15:44
197 查看
Description
You are given two polynomials:
P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an
and
Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.
Calculate limit
.
Input
The first line contains two space-separated integers n and
m (0 ≤ n, m ≤ 100) — degrees of polynomials
P(x) and Q(x) correspondingly.
The second line contains n + 1 space-separated integers — the factors of polynomial
P(x): a0,
a1, ...,
an - 1,
an( - 100 ≤ ai ≤ 100, a0 ≠ 0).
The third line contains m + 1 space-separated integers — the factors of polynomial
Q(x): b0,
b1, ...,
bm - 1,
bm( - 100 ≤ bi ≤ 100, b0 ≠ 0).
Output
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals
- ∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit
, in the format "p/q"
(without the quotes), where p is the — numerator,
q(q > 0) is the denominator of the fraction.
Sample Input
Input
Output
Input
Output
Input
Output
Input
Output
Input
Output
Sample Output
Hint
Let's consider all samples:
You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
You are given two polynomials:
P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an
and
Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.
Calculate limit
.
Input
The first line contains two space-separated integers n and
m (0 ≤ n, m ≤ 100) — degrees of polynomials
P(x) and Q(x) correspondingly.
The second line contains n + 1 space-separated integers — the factors of polynomial
P(x): a0,
a1, ...,
an - 1,
an( - 100 ≤ ai ≤ 100, a0 ≠ 0).
The third line contains m + 1 space-separated integers — the factors of polynomial
Q(x): b0,
b1, ...,
bm - 1,
bm( - 100 ≤ bi ≤ 100, b0 ≠ 0).
Output
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals
- ∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit
, in the format "p/q"
(without the quotes), where p is the — numerator,
q(q > 0) is the denominator of the fraction.
Sample Input
Input
2 1 1 1 1 2 5
Output
Infinity
Input
1 0 -1 3 2
Output
-Infinity
Input
0 1 1 1 0
Output
0/1
Input
2 2 2 1 6 4 5 -7
Output
1/2
Input
1 1 9 0 -5 2
Output
-9/5
Sample Output
Hint
Let's consider all samples:
You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
#include <stdio.h> #include <string.h> #include <math.h> int gcd(int a, int b) { if (a < b) return gcd(b, a); else if (b == 0) return a; else return gcd(b, a % b); } int main() { int n, m, P, Q, i, x, y, h; int a[1000], b[1000]; scanf("%d%d", &n, &m) ; for (i = 0; i < n + 1; i++) { scanf("%d", &a[i]); x = a[0]; } for (i = 0; i < m + 1; i++) { scanf("%d", &b[i]); y = b[0]; } if (n > m) { if ((a[0] < 0 && b[0] > 0) || (a[0] > 0 && b[0] < 0)) printf("-Infinity\n"); else if ((a[0] < 0 && b[0] < 0) || (a[0] > 0 && b[0] > 0)) printf("Infinity\n"); } else if (m > n) printf("0/1\n"); else { if (x < 0) x = x * (-1); if (y < 0) y = y * (-1); h = gcd(x, y); a[0] = a[0] / h; b[0] = b[0] / h; if ((a[0] < 0 && b[0] > 0) || (b[0] > 0 && a[0] > 0)) printf("%d/%d\n", a[0], b[0]); if ((b[0] < 0 && a[0] > 0) || (b[0] < 0 && a[0] < 0)) printf("%d/%d\n", a[0] * (-1), b[0] * (-1)); } return 0; }
相关文章推荐
- PostgreSQL 安装,使用总结
- AC算法详解
- 【CSS3】关于box-shadow的扩展半径
- OpenSSL
- 213. House Robber II【M】【60】【leetcode】
- SAP的号码范围(number range)SNRO和SNUM自动编号工具的用法
- servlet向jsp传递参数
- APK魔鬼瘦身计划
- Android 属性动画(Property Animation) 完全解析 (上)
- MySQL:MySQL日期数据类型、MySQL时间类型
- Cocoapods系列教程(二)——开源主义接班人
- 微信分享到好友或者朋友圈的截屏图片
- TextField委托方法记录(限制特定字符和限制字数)
- myeclipse更新完项目之后,JS以及JSP文件会报错
- MyEclipse10 中安装Activiti插件后,新建Activiti项目无Maven功能
- leetcode笔记:Contains Duplicate III
- 拦截器和过滤器的区
- 打印三角形,菱形
- [转] Spring注解@Component、@Repository、@Service、@Controller区别
- OpenStack 系列之File Share Service(Manila) Install Guide