codeforces Limit
来源:互联网 发布:js多行注释 编辑:程序博客网 时间:2024/06/05 14:35
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 andm (0 ≤ n, m ≤ 100) — degrees of polynomialsP(x) and Q(x) correspondingly.
The second line contains n + 1 space-separated integers — the factors of polynomialP(x): a0,a1, ..., an - 1, an( - 100 ≤ ai ≤ 100, a0 ≠ 0).
The third line contains m + 1 space-separated integers — the factors of polynomialQ(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 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
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
思路:
求 n趋于无穷大的时候函数的极限
1.长度n < m时 全部为0
2.n > m 时 分符号相反和相同两种情况
3 n = m 时 ,需要求出通分之后的结果,所以都除以最大公约数,注意同为负时,不输出负号
/*********************************************** * Author: fisty * Created Time: 2015/2/4 20:26:30 * File Name : 3_C.cpp *********************************************** */#include <iostream>#include <cstring>#include <deque>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <bitset>#include <algorithm>using namespace std;#define MAX_N 110#define Debug(x) cout << #x << " " << x <<endl#define Memset(x, a) memset(x, a, sizeof(x))const int INF = 0x3f3f3f3f;typedef long long LL;#define FOR(i, a, b) for(int i = a;i < b; i++)int P[MAX_N];int Q[MAX_N];int gcd(int a, int b){ return b == 0 ? a : gcd(b , a % b);}int main() { //freopen("in.cpp", "r", stdin); cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; for(int i = 0;i <= n; i++){ cin >> P[i]; } for(int i = 0;i <= m; i++){ cin >> Q[i]; } if(n > m){ if(P[0] < 0 && Q[0] < 0){ cout << "Infinity" << endl; }else if(P[0] < 0 && Q[0] > 0){ cout << "-Infinity" << endl; }else if(P[0] > 0 && Q[0] < 0){ cout << "-Infinity" << endl; }else{ cout << "Infinity" << endl; } }else if(n < m){ cout << 0 << "/" << 1 << endl; }else{ if(P[0] * Q[0] < 0) cout << "-"; if(P[0] < 0) P[0] *= -1; if(Q[0] < 0) Q[0] *= -1; int g = gcd(P[0], Q[0]); cout << P[0] / g << "/" << Q[0] / g << endl; } return 0;}
- codeforces Limit
- CodeForces 197B Limit
- CodeForces 197B Limit
- CodeForces NO.197B Limit
- LIMIT
- Limit
- Limit
- limit
- limit
- Codeforces Round #321 (Div. 2) C. Kefa and Park time limit per test
- Codeforces Round #321 (Div. 2) C. Kefa and Park time limit per test
- iptables limit limit-burst
- sqlite3 limit 使用limit
- Limit Speed
- sqlserver ( Limit )
- LIMIT 解释
- sql limit
- mysql limit
- 从win10体验到重装win8
- HDU 3400 - Line belt (三分)
- trace
- Unity3d(C#)错误提示:禁止在线程中进行游戏对象比较!
- C++ 虚继承
- codeforces Limit
- 单片机、P0口、上拉电阻
- Codeforces 490C Hacking Cypher(暴力)
- 了解开发手机的各项参数之显示屏
- Tzl_C#金字塔_Interface接口使用总结
- unity连接数据库工具
- ThinkPHP之getfield详解
- hdu 1005——Number Sequence
- 【机器学习】机器学习(三)——K-均值聚类