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");
        }
    }
}

 

posted @ 2019-07-31 23:09  Ldler  Views(199)  Comments(0Edit  收藏  举报