HDU - 5170 - GTY's math problem
2017-07-18 22:43
344 查看
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5170
2 4 4 2
10 10 9 11
=
<
要注意的是A-B的时候要取绝对值
题目描述
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 abSample Input
2 1 1 22 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; }
相关文章推荐
- 【CUGBACM15级BC第29场 A】hdu 5170 GTY's math problem
- hdu 5170 GTY's math problem(数学)
- HDU 5170 GTY's math problem
- HDU - 5170 GTY's math problem
- [HdOJ]5170 GTY's math problem
- HDU 5170 GTY's math problem 水题
- hdu 5170 GTY's math problem(水,,数学,,)
- HDU 5170 GTY's math problem
- HDU 1757 A Simple Math Problem
- ACM-ICPC Asia Regional Contest HDU 5974 A Simple Math Problem(数论)
- HDU 1757 A Simple Math Problem 矩阵快速幂
- 【HDU-oj】-1757-A Simple Math Problem(矩阵,十一阶)
- HDU 5170 GTY's math problem
- hdu-1757-A Simple Math Problem(矩阵快速幂入门题)
- Math Problem HDU - 5105 暴力求解/公式
- HDU 1757 A Simple Math Problem (矩阵+快速幂)
- HDU 1757 A Simple Math Problem
- Hdu 1757 A Simple Math Problem【矩阵快速幂】
- HDU 1757 A Simple Math Problem
- hdu 1757 A Simple Math Problem