HDU 5170 GTY's math problem 精度判断问题
2015-02-09 16:12
176 查看
传送门
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 568 Accepted Submission(s): 263
Problem 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,d.
The math teacher wants GTY to compare ab with cd.
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≤1000)separated
by spaces. Please process to the end of file.
Output
For each case , if ab>cd ,
print '>'. if ab<cd ,
print '<'. if ab=cd ,
print '='.
Sample Input
Sample Output
Source
BestCoder Round #29
解题方法:精度判断问题,首先a^b 和c^d是没法比的。太大了。。于是两边取log 得到log(a^b)=blog(a)
算出来后精度判断。。相减。。减出来小于1e-10就可以当做相等了
GTY's math problem
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 568 Accepted Submission(s): 263
Problem 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,d.
The math teacher wants GTY to compare ab with cd.
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≤1000)separated
by spaces. Please process to the end of file.
Output
For each case , if ab>cd ,
print '>'. if ab<cd ,
print '<'. if ab=cd ,
print '='.
Sample Input
2 1 1 2 2 4 4 2 10 10 9 11
Sample Output
> = <
Source
BestCoder Round #29
解题方法:精度判断问题,首先a^b 和c^d是没法比的。太大了。。于是两边取log 得到log(a^b)=blog(a)
算出来后精度判断。。相减。。减出来小于1e-10就可以当做相等了
#include<iostream> #include<string> #include<algorithm> #include<cstdlib> #include<cstdio> #include<set> #include<map> #include<vector> #include<cstring> #include<stack> #include<cmath> #include<queue> #define INF 0x0f0f0f0f using namespace std; #define eps 1e-12 int main() { double i,j,k,l,m,n,a,b,c,d; while(~scanf("%lf%lf%lf%lf",&a,&b,&c,&d)) { i=b*log(a); j=d*log(c); if(fabs(i-j)<eps) printf("=\n"); else if(i>j) printf(">\n"); else if(i<j) printf("<\n"); } return 0; }
相关文章推荐
- hdu 5170 GTY's math problem --精度控制
- hdu 5170 GTY's math problem【精度控制】【思维】
- HDU 5170 GTY's math problem
- HDU 5170 GTY's math problem
- hdu - 4159 - Regular Convex Polygon - 精度问题
- HDU:2031 进制转换问题
- http://acm.hdu.edu.cn/showproblem.php?pid=3591&&背包问题
- http://acm.hdu.edu.cn/showproblem.php?pid=2844&&背包问题
- http://acm.hdu.edu.cn/showproblem.php?pid=3790&&最短路径问题
- 8月22号的练习:HDU 1196&&HDU 1673&&HDU 1269&&HDU 1841(KMP)&&HDU 1176(数塔问题)
- hdu 2553 N皇后问题<java>
- HDU 1210 Eddy's 洗牌问题
- HDU 1538 A Puzzle for Pirates (博弈&海盗分赃问题)
- 在判断Request .QueryString [\"name\"]是否为空时应注意的问题
- hdu 2224 && poj 2677 (旅行商问题)
- hdu 1009 FatMouse'Trade 贪心算法 之 部分背包问题
- hdu 2110 Eddy's 洗牌问题
- hdu 1853 Cyclic Tour 求图中不相交的l个环的最小权值:首先变成完全图(i->j=inf),然后取反,求最大权值,最后判断是否所有点都选到
- HDU 2065 "红色病毒"问题 递推题 (2011-1-1 16:39)
- HDU 1824 Let's go home (2-SAT判断)