HDU-6668-Polynomial(数学)

链接:

https://vjudge.net/problem/HDU-6668

题意:

度度熊最近学习了多项式和极限的概念。
现在他有两个多项式 f(x) 和 g(x),他想知道当 x 趋近无限大的时候,f(x)/g(x) 收敛于多少。

思路:

考虑次项最高的,因为洛必达之后,上下都乘以相同值,所以只要考虑0和无收敛,

代码:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3+10;

int F[MAXN], G[MAXN];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        for (int i = 1;i <= n;i++)
            cin >> F[i];
        for (int i = 1;i <= n;i++)
            cin >> G[i];
        int pos = n;
        while (F[pos] == 0 && G[pos] == 0 && pos > 0)
            pos--;
        if (F[pos] != 0 && G[pos] == 0)
            cout << "1/0" << endl;
        else if (F[pos] == 0 && G[pos] != 0)
            cout << "0/1" << endl;
        else
            cout << F[pos]/__gcd(F[pos], G[pos]) << "/" << G[pos]/__gcd(F[pos], G[pos]) << endl;
    }

    return 0;
}
原文地址:https://www.cnblogs.com/YDDDD/p/11371755.html