百度之星初赛一--Polynomial--模拟

欢迎参加2019百度之星竞赛(点击进入报名链接)~

Polynomial

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 372    Accepted Submission(s): 159


 

Problem Description

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

 

 

Input

第一行一个整数 T (1≤T≤100) 表示数据组数。
对于每组数据,第一行一个整数 n (1≤n≤1,000) ,n−1 表示多项式 f 和 g 可能的最高项的次数(最高项系数不一定非0)。
接下来一行 n 个数表示多项式 f ,第 i 个整数 fi (0≤fi≤1,000,000) 表示次数为 i−1 次的项的系数。
接下来一行 n 个数表示多项式 g ,第 i 个整数 gi (0≤gi≤1,000,000) 表示次数为 i−1 次的项的系数。
数据保证多项式 f 和 g 的系数中至少有一项非0。

 

 

Output

对于每组数据,输出一个最简分数 a/b (a 和 b 的最大公约数为1)表示答案。
如果不收敛,输出 1/0 。

 

 

Sample Input

 

3 2 0 2 1 0 2 1 0 0 2 3 2 4 0 1 2 0

 

 

Sample Output

 

1/0 0/1 2/1 样例描述 这些多项式分别为 $f(x) = 2x$ $g(x) = 1$ $f(x) = 1$ $g(x) = 2x$ $f(x) = 4x + 2$ $g(x) = 2x + 1$

 

 

Source

2019 年百度之星·程序设计大赛 - 初赛一

 

 

Recommend

liuyiding   |   We have carefully selected several similar problems for you:  6673 6672 6671 6670 6669 

 

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>    //STL通用算法
#include <bitset>     //STL位集容器
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>     //复数类
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>      //STL双端队列容器
#include <exception>    //异常处理类
#include <fstream>
#include <functional>   //STL定义运算函数(代替运算符)
#include <limits>
#include <list>      //STL线性列表容器
#include <map>       //STL 映射容器
#include <iomanip>
#include <ios>      //基本输入/输出支持
#include<iosfwd>     //输入/输出系统使用的前置声明
#include <iostream>
#include <istream>     //基本输入流
#include <ostream>     //基本输出流
#include <queue>      //STL队列容器
#include <set>       //STL 集合容器
#include <sstream>    //基于字符串的流
#include <stack>      //STL堆栈容器    
#include <stdexcept>    //标准异常类
#include <streambuf>   //底层输入/输出支持
#include <string>     //字符串类
#include <utility>     //STL通用模板类
#include <vector>     //STL动态数组容器
#include <cwchar>
#include <cwctype>
#define ll long long
using namespace std;
//priority_queue<int,vector<int>,less<int> >q;
int dx[]= {-1,1,0,0,-1,-1,1,1};
int dy[]= {0,0,-1,1,-1,1,1,-1};
const int maxn = 1000+66;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
int n;
int gcd(int x,int y)
{
    return y==0?x:gcd(y,x%y);
}
int a[maxn];
int b[maxn];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        int x;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&b[i]);
        }
        int m=n;
        while(!a[m]&&!b[m])
        {
            m--;
        }
        if(a[m]&&!b[m])
        {
            cout<<"1/0"<<endl;
        }else if(!a[m]&&b[m])
        {
            cout<<"0/1"<<endl;
        }else
        {
            int x=gcd(a[m],b[m]);
            //cout<<x<<"--"<<endl;
            cout<<a[m]/x<<"/"<<b[m]/x<<endl;
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值