CodeForces 197B Limit
Posted jzdwajue
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces 197B Limit相关的知识,希望对你有一定的参考价值。
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
2 1 1 1 1 2 5
Infinity
1 0 -1 3 2
-Infinity
0 1 1 1 0
0/1
2 2 2 1 6 4 5 -7
1/2
1 1 9 0 -5 2
-9/5
Hint
题意:求极限。
题解:首先
P(x)?=?a0·xn?+?a1·xn?-?1?+?...?+?an?-?1·x?+?an and
Q(x)?=?b0·xm?+?b1·xm?-?1?+?...?+?bm?-?1·x?+?bm.
的极限P(x)=a0*x^n,Q(x)=b0*x^m,x->INF.
然后直接比較即可了。
注:gcd(-2,4)=-2.
#include<cstdio> #include<iostream> #include<cstring> using namespace std; #define N 110 int n,m,a[N],b[N]; int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } int main() { //printf("%d\n",gcd(-2,4)); while(cin>>n>>m) { n++,m++; for(int i=0; i<n; i++) { scanf("%d",&a[i]); } for(int j=0; j<m; j++) { scanf("%d",&b[j]); } if(n==m) { if(b[0]<0) { b[0]=-b[0]; a[0]=-a[0]; } int x=gcd(a[0],b[0]); if(x<0)x=-x; printf("%d/%d\n",a[0]/x,b[0]/x); } else if(n>m) { if(a[0]>0&&b[0]>0||(a[0]<0&&b[0]<0))printf("Infinity\n"); else printf("-Infinity\n"); } else { printf("0/1\n"); } } }
以上是关于CodeForces 197B Limit的主要内容,如果未能解决你的问题,请参考以下文章
CodeForces 437B The Child and Set