BestCoder Round#29 1001 GTY's math problem
2015-03-15 10:51
351 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5170
其实思路不难,若想比较这两个数,直接快速幂的话会爆数,所以可以取对数比较。
因为对数计算后得到的数为浮点数,则接下来就是浮点数比较大小的问题了。
有浮点数a,b。
a==b,则fabs(a-b)<ESP
a>b,则a-b>ESP
a<b,则b-a>ESP
代码如下
其实思路不难,若想比较这两个数,直接快速幂的话会爆数,所以可以取对数比较。
因为对数计算后得到的数为浮点数,则接下来就是浮点数比较大小的问题了。
有浮点数a,b。
a==b,则fabs(a-b)<ESP
a>b,则a-b>ESP
a<b,则b-a>ESP
代码如下
#include <iostream> #include <iomanip> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <vector> #include <stack> #include <string> #include <cstring> using namespace std; const int maxn=222222; const int INF=0x7fffffff; #define LSON l,m,rt<<1 #define RSON m+1,r,rt<<1|1 #define ESP 1e-7 double hanshu(int a, int b) { return 1.0*b*log((double)a); } int main() { int a,b,c,d; while(scanf("%d%d%d%d", &a, &b, &c, &d)!=EOF) { double x=hanshu(a, b), y=hanshu(c, d); if(fabs(x-y)<ESP) puts("="); else if(x-y>ESP) puts(">"); else puts("<"); } return 0; }
相关文章推荐
- BestCoder Round #29——A--GTY&#39;s math problem(快速幂(对数法))、B--GTY&#39;s birthday gift(矩阵快速幂)
- 【BestCoder】#29 C GTY's gay friends(区间和 随机数判重)
- 【Best Coder】#29 B GTY's birthday gift(快速幂|mod的时候记得负!)
- BestCoder Round #29——A--GTY's math problem(快速幂(对数法))、B--GTY's birthday gift(矩阵快速幂)
- HDU5105 Math Problem && BestCoder Round #18 1002
- BestCoder Round 69 Div 2 1001&& 1002 || HDU 5610 && 5611
- BestCoder Round #70 1002 Jam's balance(DP)
- HDU 5104 Primes Problem(拆分素数和问题)【BestCoder Round #18 1001】
- GTY's math problem (BestCoder Round #29 A)
- BestCoder Round #75 King's Cake 模拟&&优化 || gcd
- BestCoder Round #70 Jam's store(网络流)
- BestCoder Round #65 ZYB's Game
- BestCoder Round #75 T3 King's Order HDOJ 5642
- HDU5104 Primes Problem && BestCoder Round #18 1001
- hdu 5274 Dylans loves tree && BestCoder Round #45
- 【BestCoder】 HDOJ 5055 Bob and math problem
- BestCoder #Valentine's Day Round 1001 || hdu 5174
- BestCoder Round 38-1001 Four Inages Strategy
- [Bestcoder] Valentine's Day Round 1001 - Ferries Wheel | HDU 5174
- hdu 5196 DZY Loves Inversions && BestCoder Round #35