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 1296 Polynomial Problem(多项式模拟)
Problem Description We have learned how to obtain the value of a polynomial when we were a middle sc ...
- 遗传算法,实数编码的交叉操作之SBX(模拟二进制交叉)
本文主要介绍遗传算法(实数编码)的交叉操作中的SBX,模拟二进制交叉. 首先,给出个人用python2.7实现的代码,具体模块已上传到: https://github.com/guojun007/sb ...
- 【数论】UVa 10586 - Polynomial Remains
Problem F: Polynomial Remains Given the polynomial a(x) = an xn + ... + a1 x + a0, compute the remai ...
- poj1472[模拟题]
Instant Complexity Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2017 Accepted: 698 ...
- UVALive 4119 Always an integer (差分数列,模拟)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Always an integer Time Limit:3000MS M ...
- ASP.NET Core 一步步搭建个人网站(5)_Api模拟和网站分析
前言 经过前面几章,我们的网站已经最基本的功能,接下来就是继续拓展其他的功能,这期一起来实现一个该网站流量分析的工具,统计出这个网站每天用户相关数据,不仅要满足了我们对流量统计数字的基本要求,并且用更 ...
- 数据拟合:多项式拟合polynomial curve fitting
http://blog.csdn.net/pipisorry/article/details/49804441 常见的曲线拟合方法 1.使偏差绝对值之和最小 2.使偏差绝对值最大的最小 3 ...
- 标准遗传算法(实数编码 python实现)模拟二进制交叉SBX 多项式变异
代码地址: https://github.com/guojun007/real_sga 本部分是采用实数编码的标准遗传算法,整体流程与上一篇二进制编码的基本一致, 主要区别在于本部分的交叉操作为模拟二 ...
- 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 ...
随机推荐
- It's strange. I felt less lonely when I didnt know you.
feasible:adj. 可行的 bypass: v. 绕开,避开 eclipse: n. 月食 raw: adj. 生的 foresee:v. 预见 premier:n. 总理 ,adj: 首要的 ...
- PL/SQL Developer 报错Dynamic Performance Tables not accessible, Automatic Statistics disabled for this session You can disable statistics in the preference menu, or obtain select priviliges on the V$ses
可以从以下几个方面考虑: 1)单独给用户授动态性能视图的权限: SQL> grant select on V_session to user; SQL> grant select on ...
- Spring Boot & Restful API 构建实战!
作者:liuxiaopeng https://www.cnblogs.com/paddix/p/8215245.html 在现在的开发流程中,为了最大程度实现前后端的分离,通常后端接口只提供数据接口, ...
- stl(set或map)
https://nanti.jisuanke.com/t/41384 There are nnn points in an array with index from 111 to nnn, and ...
- Python学习第四十一天函数装饰器传参数的用法
在不改变函数的结构的基础,我们给函数加新的功能,用是函数装饰器,如果要给函数传递参数,那么应该怎么做呢 @timerdef test2(name,age): time.sleep(3) print(' ...
- Windows Server 搭建企业无线认证(NPS搭建)
现代企业无线网络是必备,移动办公更是需求日益剧增.而带来的无线网络安全隐患随之而来,也是面临着巨大的挑战.所以对无线网络做接入认证是现在企业很迫切的需求. 上一遍已经说明了Radius认证方案:htt ...
- HBase构架原理
HBase的概念: HBase在生态圈位置 HBase与HDFS对比 HBase与关系型数据库的比较 HBase表的特点: 4)任意模式:每一行都有一个可排序的主键和任意多的列,列可以根据自己的需要动 ...
- [书接上一回]在Oracle Enterprise Linux (v5.7) 中安装DB - (4/4)
选择自己创建的安装数据库路径. Sample Schemas 打钩. 调整内存大小. 选择官方建议的字符集编码. 是否创建创建的脚本,如需要请打钩. 脚本生成成功. 创建成功,如需要,则可以管理数据库 ...
- sqoop使用中文手册
文章转载自:http://www.zihou.me/html/2014/01/28/9114.html 1. 概述 本文档主要对SQOOP的使用进行了说明,参考内容主要来自于Cloudera ...
- Oracle Grid,ASM,Database on Redhat 7.5
目录 Oracle安装包 Oracle官方文档 Blog Oracle Grid Installation Process 用户.组.目录 Oracleasm 创建 ASM 磁盘 Database S ...