您的位置:首页 > 其它

HDU - 5170 - GTY's math problem

2017-07-18 22:43 344 查看
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5170

题目描述

Description

GTY is a GodBull who will get an Au in NOI . To have more time to learn algorithm knowledge, he never does his math homework. His math teacher is very unhappy for that, but she can’t do anything because GTY can always get a good mark in math exams. One day, the math teacher asked GTY to answer a question. There are four numbers on the blackboard - a,b,c,da,b,c,d. The math teacher wants GTY to compare abab with cdcd. Because GTY never does his homework, he can’t figure out this problem! If GTY can’t answer this question correctly, he will have to do his homework. So help him!

Input

Multi test cases (about 5000). Every case contains four integers a,b,c,d(1≤a,b,c,d≤10001≤a,b,c,d≤1000)separated by spaces. Please process to the end of file.

Output

For each case , if ab>cdab>cd , print ‘>’. if ab

Sample Input

2 1 1 2

2 4 4 2

10 10 9 11

Sample Output

>

=

<

解题思路

比较 a^b c^d 的大小,因为数据很大,如果用pow(a, b)的话肯定会爆,两边同时去log,以几为底无所谓,这样的话就可以吧指数放在前面相乘,设想如果数A-数B<0.0000000000000000000001 一个很小很小的数,可以看做这两个数相等(当然没有这么多0),有了这个想法就好做了

要注意的是A-B的时候要取绝对值

AC代码

#include<iostream>
#include<cmath>
#define MIX 1e-10
using namespace std;
int main () {
int a, b, c, d;
while(~scanf("%d %d %d %d", &a, &b, &c, &d)) {
double index1 = b*log10(a);
double index2 = d*log10(c);
if(fabs(index1 - index2) < MIX) printf("=\n");
else if(index1 > index2) printf(">\n");
else printf("<\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: