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. TensorFlow学习笔记11-开始用TensorFlow

    TensorFlow运作方式 要用到的代码都在Github上.当然,如果你本地装了TensorFlow,也可以用Everything直接搜索以下文件: mnist.py fully_connected ...

  2. python+selenium的WebElement对象操作

    webelement对象操作 webelement对象是selenium中所有元素的父类,也就是webelement对象拥有的方法,其它元素对象都会有: 只是不同的对象在调用特定方法时,效果是不一样的 ...

  3. Maven 修改jdk版本

    Maven 修改jdk版本方法1: <build> <plugins> <plugin> <groupId>org.apache.maven.plugi ...

  4. Java-Lambda表达式第一篇认识Lambda表达式

    1.Lambda表达式时Java 8新增的特性.Lambda表达式支持将代码块作为方法参数,Lambda表达式允许使用更简洁的代码创建只有一个抽象方法的接口(即函数式接口)的实例. 2.当使用Lamb ...

  5. Developer Express 第三方控件使用系列方法

    本人目前从事的开发工作主要是以C#语言进行的相关C/S的开发,在工作中也要求使用Developer Express第三方控件所以这一系列的控件使用说明都将以C#语言进行代码说明.平时工作中会慢慢的收集 ...

  6. 回溯---Permutations II

    47.Permutations II (Medium)](https://leetcode.com/problems/permutations-ii/description/) [1,1,2] hav ...

  7. Ftp客户端(上传文件)

    #coding=utf-8 import os import socket import hashlib import json # client = socket.socket() #申明socke ...

  8. 如何设置移动端的tab栏

    这是添加tab栏的代码: {                     "id": "tabBar1",                     "st ...

  9. 深入JavaScript之获取cookie以及删除cookie

    cookie存在哪? 存在document.cookie中 ookie长啥样? cookie是一个字符串,长下面这样:“name=xxx; age=22;” 注意:分号后面有个空格,记住这一点,下面的 ...

  10. linux测试 Sersync 是否正常

    [root@SERSYNC web]# for i in {1..10000};do echo 123456 > /data/web/$i &>/dev/null;do ne [r ...