Fraction Comparision
题意:输入x,a,y,b求x/a和y/b的大小,范围long long int
思路:因为不想用精度,嫌麻烦,所以用了个巧方法。先求x/a和y/b整形的大小,如果相等,再求(x%a)*b和(y%b)*a的大小,具体为什么可以这样比较,初中生都会。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<string>
#define ll long long
using namespace std;
int main()
{
ll x,y,a,b;
while(scanf("%lld%lld%lld%lld",&x,&a,&y,&b)!=EOF)
{
ll z1=x/a;
ll z2=y/b;
if(z1>z2)
{
printf(">\n");
}
else if(z1<z2)
{
printf("<\n");
}
else
{
ll y1=x%a;
ll y2=y%b;
ll r1=y1*b;
ll r2=y2*a;
if(r1==r2)
printf("=\n");
if(r1>r2)
printf(">\n");
if(r1<r2)
printf("<\n");
}
}
}
Fraction Comparision的更多相关文章
- ZJUT11 多校赛补题记录
牛客第一场 (通过)Integration (https://ac.nowcoder.com/acm/contest/881/B) (未补)Euclidean Distance (https://ac ...
- 2019牛客暑期多校第一场题解ABCEFHJ
A.Equivalent Prefixes 传送门 题意:给你两个数组,求从第一个元素开始到第p个元素 满足任意区间值最小的元素下标相同的 p的最大值. 题解:我们可以从左往右记录到i为止每个区间的最 ...
- 2019牛客多校 Round1
Solved:4 Rank:143 A Equivalent Prefixes 题意:求一个最大的r满足在A,B两个数组中1,r里所有的子区间RMQ相等 题解:单调队列秒 #include <b ...
- [LeetCode] Fraction to Recurring Decimal 分数转循环小数
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- 【leetcode】Fraction to Recurring Decimal
Fraction to Recurring Decimal Given two integers representing the numerator and denominator of a fra ...
- Decimal To Fraction 小数转换成分数
以0.25为例, 0.25 * 100 = 25, 求25 和 100 的最大公约数gcd. 25/gcd 为分子. 100/gcd为分母. //小数转分数 //0.3 -> 3/10, 0.2 ...
- ✡ leetcode 166. Fraction to Recurring Decimal 分数转换 --------- java
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- Leetcode 166. Fraction to Recurring Decimal 弗洛伊德判环
分数转小数,要求输出循环小数 如2 3 输出0.(6) 弗洛伊德判环的原理是在一个圈里,如果一个人的速度是另一个人的两倍,那个人就能追上另一个人.代码中one就是速度1的人,而two就是速度为2的人. ...
随机推荐
- poj2377Bad Cowtractors (最小生成树变形之——最大生成树)
题目链接:http://poj.org/problem?id=2377 Description Bessie has been hired to build a cheap internet netw ...
- SPOJ NICEBTRE - Nice Binary Trees(树 先序遍历)
传送门 Description Binary trees can sometimes be very difficult to work with. Fortunately, there is a c ...
- Robotframework使用自写库连接mysql数据库
Robotframework使用自写库连接mysql数据库 新建库文件mysqltest.py 代码如下: # -*- coding: utf-8 -*- import MySQLdbimport o ...
- mybatis配置mapper.xml 的基本操作
XML 映射文件 本文参考mybatis中文官网进行学习总结:http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html MyBatis 的真正强大在于它的 ...
- django的orm操作优化
django的orm操作优化 models.py from django.db import models class Author(models.Model): name = models.Char ...
- python第一部分小结
1.python的种类 Cpython: ...
- 合并石子 (区间dp+前缀和)
[题目描述] N堆石子.现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆石子合并成新的一堆,并将新的一堆石子数记为该次合并的得分.计算出将N堆石子合并成一堆的最小得分. [题目链接] http: ...
- 关于Myeclipse下的JVM启动异常的问题:Out Of Memery / Could not reserve enough space for object heap
以下都是初步理解: 这主要是JVM内存配置的问题,网上有很多参考资料,但是我们不能死板硬套,必须根据自己工程的实际情况配置相关的参数. 1.按照jvm的设计规则,JVM内存分为堆(Heap)和非堆(N ...
- java中关于异常的处理
初学java的时候,当我们碰到异常时,一般会把异常直接throws抛出去,或则在catch的时候,简单的写一句打印异常信息,但是在实际开发中,是不能这么做的.如果我们将底层的某一个异常简单的print ...
- IntelliJ IDEA 中 Ctrl+Alt+Left/Right 失效
开发工具:Idea OS:Window 7 在idea中使用ctrl+b跟踪进入函数之后,每次返回都不知道用什么快捷键,在idea中使用ctrl+alt+方向键首先会出现与win7屏幕方向的快捷键冲突 ...