标签:遍历 ace 情况 for mat using print inline amp
顺序遍历找出最高次幂项的系数
分三种情况 \(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;
}
标签:遍历 ace 情况 for mat using print inline amp
原文地址:https://www.cnblogs.com/solvit/p/11372928.html