Codeforces Round #124 (Div. 2)
来源:互联网 发布:在职研究生研修班 知乎 编辑:程序博客网 时间:2024/06/05 20:02
B. Limit
给定两个多项式的系数,求当x趋向正无穷时,两个多项式相比的极限。正无穷则输出"Infinity" ,负无穷则输出"-Infinity" ,若极限为0则输出"0/1" ,分情况讨论即可。学会用递归求最大公约数。最高阶数相等的情况下则一定存在极限,若最高系数符号相异,则极限一定是负的,反之为正的。在求解极限的时候其实不用求最大公约数也能得到正确的答案,比如说6/2就等于3/1,之所以求解最大公约数无非是为了满足和预设的答案一致罢了。
#include<iostream>#include<cmath>using namespace std;#define N 105 int gcd(int a, int b)//递归,返回值为a,b最大公约数{return b == 0 ? a : gcd(b, a%b);}int main(){int n, m, i;cin >> n >> m;int a[105], b[105];for (i = 0; i <= n; i++)cin >> a[i];for (i = 0; i <= m; i++)cin >> b[i];if (n == m)//阶数一致的情况{if (a[0] * b[0]<0)cout << "-";cout << abs(a[0]) / gcd(abs(a[0]), abs(b[0])) << "/" << abs(b[0]) / gcd(abs(a[0]), abs(b[0])) << endl;;}else if (n>m)//分子阶数更高{if (a[0] * b[0] < 0)cout << "-";cout << "Infinity" << endl;}elsecout << "0/1" << endl;return 0;}再仔细看看求解最大公约数的函数,当作一个积累吧:
int gcd(int a, int b)//递归,返回值为a,b最大公约数{return b == 0 ? a : gcd(b, a%b);}
0 0
- Codeforces Round #124 (Div. 2)
- Codeforces Round #124 (Div. 2)
- Codeforces Round #124 (Div. 2)
- Codeforces Round #124 (Div. 2)
- Codeforces Round #124 (Div. 2) (Div.1)
- Codeforces Round #124 (Div. 1)
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- Codeforces Round #122 (Div. 2)
- Codeforces Round #121 (Div. 2)
- Codeforces Round #125 (Div. 2)
- 怎样VS2013下安装Qt5的插件
- flexpaper全屏缩放后 浏览器滚动条失效
- 杭电 2141 Can you find it?二分法+暴力查找
- HDU 5336 XYZ and Drops
- RSA ENCRYPT
- Codeforces Round #124 (Div. 2)
- final变量
- select用法详解 http://blog.chinaunix.net/uid-23373524-id-2426940.html
- 【数据结构】红黑树
- hdu5328 最长的连续的等比或等差数列
- 从字节码指令看重写在JVM中的实现
- Android内存泄漏分析及调试
- VS2010(64)+Qt4.8.0+PCL1.6.0+Vtk配置显示点云
- poj1064 Cable master(hdoj1551)