codeforce341 D题 Rat Kwesh and Cheese(复数)

题意

计算出由x,y,z构成的下标最小的 值最大的表达式。
0.1 ≤ x, y, z ≤ 200.0

思路

因为 xyz 可能非常大,所以需要使用2次log函数。可以将 xyz 转换成 zlog(y)+log(log(x)) 但是如果x小于1的时候log(x) 是小于0的。 所以参考别人的思路后,觉得是可以使用复数来解决。 任何一个复数 a+bi 的对数都可以表示成 lnr+iθ 。对于2个负数,如果值越大,则r越小,则其log值得实部越小。

代码

(原大牛作者版本http://codeforces.com/profile/thuustalu

#include <iostream>
#include <complex>
#include <string>

using namespace std;

bool bigger (complex<long double> a, complex<long double> b) {
  if (imag(a) == 0 && imag(b) == 0) {
    return real(a) > real(b);
  } else if (imag(a) == 0 && imag(b) != 0) {
    return true;
  } else if (imag(a) != 0 && imag(b) == 0) {
    return false;
  } else if (imag(a) != 0 && imag(b) != 0) {
    return real(a) < real(b);
  }
}

int main () {
  long double ax, ay, az;
  cin >> ax >> ay >> az;

  complex<long double> x (ax, 0.0L);
  complex<long double> y (ay, 0.0L);
  complex<long double> z (az, 0.0L);

  complex<long double> cmaz (3, 3);
  string ans = "xd";

  if (bigger(z * log(y) + log(log(x)), cmaz)) {
    cmaz = z * log(y) + log(log(x));
    ans = "x^y^z";
  }
  if (bigger(y * log(z) + log(log(x)), cmaz)) {
    cmaz = y * log(z) + log(log(x));
    ans = "x^z^y";
  }
  if (bigger(log(y * z) + log(log(x)), cmaz)) {
    cmaz = log(y * z) + log(log(x));
    ans = "(x^y)^z";
  }

  if (bigger(z * log(x) + log(log(y)), cmaz)) {
    cmaz = z * log(x) + log(log(y));
    ans = "y^x^z";
  }
  if (bigger(x * log(z) + log(log(y)), cmaz)) {
    cmaz = x * log(z) + log(log(y));
    ans = "y^z^x";
  }
  if (bigger(log(x * z) + log(log(y)), cmaz)) {
    cmaz = log(x * z) + log(log(y));
    ans = "(y^x)^z";
  }

  if (bigger(y * log(x) + log(log(z)), cmaz)) {
    cmaz = y * log(x) + log(log(z));
    ans = "z^x^y";
  }
  if (bigger(x * log(y) + log(log(z)), cmaz)) {
    cmaz = x * log(y) + log(log(z));
    ans = "z^y^x";
  }
  if (bigger(log(x * y) + log(log(z)), cmaz)) {
    cmaz = log(x * y) + log(log(z));
    ans = "(z^x)^y";
  }

  cout << ans << endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值