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(模拟)的更多相关文章

  1. hdu 1296 Polynomial Problem(多项式模拟)

    Problem Description We have learned how to obtain the value of a polynomial when we were a middle sc ...

  2. 遗传算法,实数编码的交叉操作之SBX(模拟二进制交叉)

    本文主要介绍遗传算法(实数编码)的交叉操作中的SBX,模拟二进制交叉. 首先,给出个人用python2.7实现的代码,具体模块已上传到: https://github.com/guojun007/sb ...

  3. 【数论】UVa 10586 - Polynomial Remains

    Problem F: Polynomial Remains Given the polynomial a(x) = an xn + ... + a1 x + a0, compute the remai ...

  4. poj1472[模拟题]

    Instant Complexity Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2017   Accepted: 698 ...

  5. UVALive 4119 Always an integer (差分数列,模拟)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Always an integer Time Limit:3000MS     M ...

  6. ASP.NET Core 一步步搭建个人网站(5)_Api模拟和网站分析

    前言 经过前面几章,我们的网站已经最基本的功能,接下来就是继续拓展其他的功能,这期一起来实现一个该网站流量分析的工具,统计出这个网站每天用户相关数据,不仅要满足了我们对流量统计数字的基本要求,并且用更 ...

  7. 数据拟合:多项式拟合polynomial curve fitting

    http://blog.csdn.net/pipisorry/article/details/49804441 常见的曲线拟合方法 1.使偏差绝对值之和最小 2.使偏差绝对值最大的最小       3 ...

  8. 标准遗传算法(实数编码 python实现)模拟二进制交叉SBX 多项式变异

    代码地址: https://github.com/guojun007/real_sga 本部分是采用实数编码的标准遗传算法,整体流程与上一篇二进制编码的基本一致, 主要区别在于本部分的交叉操作为模拟二 ...

  9. Polynomial ( Arithmetic and Algebra) CGAL 4.13 -User Manual

    1 Fundamentals A polynomial is either zero, or can be written as the sum of one or more non-zero ter ...

随机推荐

  1. 一些输出、处理细节&注意点

    https://blog.csdn.net/qq_41071646/article/details/79953476 输出百分比的时候,结果需要加上一个EPS(1e-6)四舍五入保证精度. 卡精度—— ...

  2. SpringBoot使用webservice

    Pom.xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spr ...

  3. [Python3] 009 字符串:给你们看看我的内置方法 第一弹

    目录 前言 如何查看 python3 中和 str 有关的方法 字符串方法 1. capitalize() 2. casefold() 3. center(width) 4. count(sub[, ...

  4. python工程的结构

    1 python系统库的位置 大部分系统库在/usr/lib64/python2.7目录下,但是像sys模块,是python内置的库,是用c实现的,直接连接进了python.exe中了. 也就是说,在 ...

  5. body传参?parameter传参?Request Payload?Query String Parameter?

    今天,是有委屈的一天:今天,是有小情绪的一天.所以,我们要对今天进行小结,跟它做一个了断! 今天,后端来一个接口,告诉我"要用post请求,parameter形式传参".over. ...

  6. ES6——generator-yield

    yield 既可传参,又可以返回 第一个next()传参无效,只用来启动 如果函数前漏掉 * 就是普通函数 如果有yield会报错, ReferenceError: yield is not defi ...

  7. jquery 在页面上根据ID定位(jQuery锚点跳转及相关操作)

    JQuery下锚点的平滑跳转 对于锚点的平滑跳转,在一般的商业性质的网站上,权衡来说,要谨慎使用. 例如:让页面平滑滚动到一个id为box的元素处,则JQuery代码只要一句话,关键位置 如下: $( ...

  8. iOS 应用配置及证书生成教程

    简介 首先你需要有一个苹果的开发者帐号,一台苹果电脑.点击查看苹果开发者账号注册流程 本教程需完成应用信息配置,包括如下两个基本配置: AppID Bundle ID 同时,生成 如下三个证书文件及对 ...

  9. 2018-8-10-使用-Resharper-特性

    title author date CreateTime categories 使用 Resharper 特性 lindexi 2018-08-10 19:16:51 +0800 2018-4-25 ...

  10. LNMP集群架构篇

    一.LNMP介绍 1.使前端web服务和后端存储服务进行串联 2.主要实现处理php动态请求 工作原理: L:linux  N:nginx  M:mysql   P:php 二.lnmp部署 我的环境 ...