zoukankan      html  css  js  c++  java
  • NCD 2019 M. NCD Salary

    • 题意 :给你两个指数类型的数\(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;
      }
      
  • 相关阅读:
    C++结构体内重载、this指针和友元函数(初步了解)
    数据结构—造树计划—二叉搜索树
    PTA顺序的分数
    PTA兼容任务
    PTA航船
    UML-基于GRASP对象设计步骤
    UML-设计对象时涉及的制品有哪些?
    UML-什么是用例实现(场景实现)?
    UML-如何使用GRASP进行对象设计?
    日志总结
  • 原文地址:https://www.cnblogs.com/lr599909928/p/12830548.html
Copyright © 2011-2022 走看看