Codeforces Round #124 (Div. 2)——B
来源:互联网 发布:如何更改淘宝店招 编辑:程序博客网 时间:2024/06/05 17:45
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 .
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).
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.
2 11 1 12 5
Infinity
1 0-1 32
-Infinity
0 111 0
0/1
2 22 1 64 5 -7
1/2
1 19 0-5 2
-9/5
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;}
- Codeforces Round #124 (Div. 2)——B
- Codeforces Round #154 (Div. 2)——B
- Codeforces Round #156 (Div. 2)——B
- Codeforces Round #151 (Div. 2)——B
- Codeforces Round #152 (Div. 2)——B
- Codeforces Round #149 (Div. 2)——B
- Codeforces Round #146 (Div. 2)——B
- Codeforces Round #144 (Div. 2)——B
- Codeforces Round #142 (Div. 2)——B
- Codeforces Round #157 (Div. 2)——B
- Codeforces Round #134 (Div. 2)——B
- Codeforces Round #141 (Div. 2)——B
- Codeforces Round #140 (Div. 2)——B
- Codeforces Round #137 (Div. 2)——B
- Codeforces Round #136 (Div. 2)——B
- Codeforces Round #135 (Div. 2)——B
- Codeforces Round #123 (Div. 2)——B
- Codeforces Round #117 (Div. 2)——B
- DRBD使用总结
- 下载vsftp地址
- Linus的最新愤怒,这哥们真心触碰到了Linus的底线
- 关于linux进程调度的公平性
- Chromium源代码工程目录分析
- Codeforces Round #124 (Div. 2)——B
- div中的文字居中代码
- IOS PUSH 的视频讲座
- sizeof和strlen测试
- gentoo上使用sudo
- TMD,找个换行方法都找了几分钟
- nginx rewrite 参数和例子
- 对线性回归,logistic回归和一般回归的认识
- Continuation 和高级流程控制