Codeforces Round #124 (Div. 2)——B

来源:互联网 发布:如何更改淘宝店招 编辑:程序博客网 时间:2024/06/05 17:45
B. Limit
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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)a0a1, ..., an - 1an ( - 100 ≤ ai ≤ 100, a0 ≠ 0).

The third line contains m + 1 space-separated integers — the factors of polynomial Q(x)b0b1, ..., bm - 1bm ( - 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 test(s)
input
2 11 1 12 5
output
Infinity
input
1 0-1 32
output
-Infinity
input
0 111 0
output
0/1
input
2 22 1 64 5 -7
output
1/2
input
1 19 0-5 2
output
-9/5
Note

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 <iostream>#include <cstdio>#include <algorithm>using namespace std;#define maxn 120int a[maxn];int b[maxn];int gcd(int x,int y){    if(x<y) swap(x,y);    int r;    while(1)    {        r=x%y;        if(r==0) break;        x=y;        y=r;    }    return y;}int main(){    int n,m,i;    scanf("%d%d",&n,&m);    for(i=0; i<=n; i++)        scanf("%d",a+i);    for(i=0; i<=m; i++)        scanf("%d",b+i);    if(n>m)    {        if(a[0]*b[0]<0) printf("-");        printf("Infinity\n");        return 0;    }    if(n<m)    {        printf("0/1\n");        return 0;    }    if(a[0]*b[0]<0) printf("-");    if(a[0]<0) a[0]*=(-1);    if(b[0]<0) b[0]*=(-1);    int yushu=gcd(a[0],b[0]);    printf("%d/%d\n",a[0]/yushu,b[0]/yushu);    return 0;}

原创粉丝点击