HDU6668 Polynomial(模拟)

Posted solvit

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU6668 Polynomial(模拟)相关的知识,希望对你有一定的参考价值。

HDU6668 Polynomial

顺序遍历找出最高次幂项的系数

分三种情况 \(1/0\)\(0/1\)\(f(x)/g(x)\)

复杂度为 \(O(n)\)

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>

using namespace std;

const int maxn = 1005;
int t, n, f_num, f_id, g_num, g_id;
int f[maxn], g[maxn];

int gcd(int a, int b)
    return b ? gcd(b, a % b) : a;

int main()

    scanf("%d", &t);
    for(int cas = 1; cas <= t; cas++)
        scanf("%d", &n);
        f_id = g_id = 0;
        for(int i = 1; i <= n; i++)
            scanf("%d", &f[i]);
            if(f[i] > 0)
                f_num = f[i];
                f_id = i;
            
        
        for(int i = 1; i <= n; i++)
            scanf("%d", &g[i]);
            if(g[i] > 0)
                g_num = g[i];
                g_id = i;
            
        
        if(f_id < g_id)
            puts("0/1");
        
        else if(f_id > g_id)
            puts("1/0");
        
        else
            int d = gcd(f_num, g_num);
            printf("%d/%d\n", f_num / d, g_num / d);
        
    
    return 0;

以上是关于HDU6668 Polynomial(模拟)的主要内容,如果未能解决你的问题,请参考以下文章

HDU-6668-Game 百度之星第一场B

PRML 学习: Polynomial Curve Fitting

PRML 学习: Polynomial Curve Fitting

PRML 学习: Polynomial Curve Fitting

hdu 2778 LCR 模拟题

hdu6034[模拟] 2017多校1