NCD 2019 M. NCD Salary
2024-10-19 06:39:21
题意 :给你两个指数类型的数\(A^m\)和\(B^n\),比较他们的大小.保证底数和指数中最多只有一个为0.
题解 :题目数据非常大,肯定不能直接比较.由换底公式和\(Log\)函数的性质我们知道:\(LogA^m=mLogA\),又因为\(Log\)函数是单增的,我们便可以用它来进行大小的比较.这里要注意当底数为0的时候,指数为0可以不用管.还有要记住!!! double类型比较大小会出现精度的问题,不能直接比,要用一个eps!!!
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL; const double eps=1e-8;
int t;
double res1,res2;
int b1,p1,b2,p2; int main() {
ios::sync_with_stdio(false);
cin>>t;
while(t--){
cin>>b1>>p1>>b2>>p2;
if(b1==0 || b2==0){
if(b1>b2) puts("HaHa");
else if(b1<b2) puts("Congrats");
else puts("Lazy");
continue;
}
res1=log(1.0*b1)*p1*1.0;
res2=log(1.0*b2)*p2*1.0;
if(fabs(res1-res2)<eps) puts("Lazy");
else if(res1<res2) puts("Congrats");
else puts("HaHa");
}
return 0;
}
最新文章
- 无法解决“Microsoft.SharePoint.Security, Version=15.0.0.0,”与“Microsoft.SharePoint.Security, Version=14.0.0.0”之间的冲突
- 结构体内嵌函数指针实现C语言面向对象
- JS详细入门教程(上)
- JDBC + MySQL 示例
- Cdnbes负载均衡的权重用法解释
- RequireJS 循环依赖报 模块undefined 处理方案
- SQL基础巩固1
- VBS定时关闭的弹窗
- JAVA_BaseDAO数据处理类
- TVideoGrabber的使用(一)捕捉摄像头
- centos6.5 64bit 实现root开机自动登录X桌面
- 关于TCP协议握手的那些事儿
- 我的日常工具——gdb篇
- 【转】selenium及webdriver的原理
- 黑马程序员 c#单态的设计模式 (专题二)
- ImageView的子类无法加载图片
- Neutron网络-OPENSTACK讲得比较透和方便
- MongoDB Sharding
- LeetCode &; Q14-Longest Common Prefix-Easy
- Python内置函数(40)——map