Codeforces Round #341 (Div. 2) Editorial D - Rat Kwesh and Cheese(数学,高精度)

来源:互联网 发布:java join 编辑:程序博客网 时间:2024/06/08 12:18

题目链接
D. Rat Kwesh and Cheese
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Wet Shark asked Rat Kwesh to generate three positive real numbers xy and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point.

Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to earn a lot of cheese. He will hand the three numbers xy and z to Rat Kwesh, and Rat Kwesh will pick one of the these twelve options:

  1. a1 = xyz
  2. a2 = xzy
  3. a3 = (xy)z
  4. a4 = (xz)y
  5. a5 = yxz
  6. a6 = yzx
  7. a7 = (yx)z
  8. a8 = (yz)x
  9. a9 = zxy
  10. a10 = zyx
  11. a11 = (zx)y
  12. a12 = (zy)x

Let m be the maximum of all the ai, and c be the smallest index (from 1 to 12) such that ac = m. Rat's goal is to find that c, and he asks you to help him. Rat Kwesh wants to see how much cheese he gets, so he you will have to print the expression corresponding to that ac.

Input

The only line of the input contains three space-separated real numbers xy and z (0.1 ≤ x, y, z ≤ 200.0). Each of xy and z is given with exactly one digit after the decimal point.

Output

Find the maximum value of expression among xyzxzy(xy)z(xz)yyxzyzx(yx)z(yz)xzxyzyx(zx)y(zy)x and print the corresponding expression. If there are many maximums, print the one that comes first in the list. 

xyz should be outputted as x^y^z (without brackets), and (xy)z should be outputted as (x^y)^z (quotes for clarity). 

Examples
input
1.1 3.4 2.5
output
z^y^x
input
2.0 2.0 2.0
output
x^y^z
input
1.9 1.8 1.7
output
(x^y)^z

题意

0.1x,y,z200.012x,y,z ,,序号的。


题解:

double次方可以用库函数pow解决。

由于200^(200^200)非常大,所以不能直接算,首先至少要取一次log。

用取一次log大方法并用long double存可以过。

不过取完一次log后200^200还是非常大。

那么考虑取两次log,不过此时就有个问题,由于取log得数必须为正,如果第一次取log的底数小于1,那么就不能直接取第二次log。

这是官方题解:

We need a way to deal with xyz and xyz. We cannot directly compare them, 200200200 is way too big. So what we do? Take log!  is an increasing function on positive numbers (we can see this by taking , then , which is positive when we are dealing with positive numbers). So if , then x ≥ y.

When we take log,  But yz can still be 200200, which is still far too big. So now what can we do? Another log! But is it legal? When x = 0.1 for example, , so we cannot take another log. When can we take another log, however? We need  to be a positive number. yz will always be positive, so all we need is for  to be positive. This happens when x > 1. So if x, y, z > 1, everything will be ok. 

There is another good observation to make. If one of x, y, z is greater than 1, then we can always achieve some expression (out of those 12) whose value is greater than 1. But if x < 1, then xa will never be greater than 1. So if at least one of x, y, z is greater than 1, then we can discard those bases that are less than or equal to 1. In this case, . Remember that , so . Similarly, .

The last case is when x ≤ 1, y ≤ 1, z ≤ 1. Then, notice that for example,. But the denominator of this fraction is something we recognize, because 10 / 3 > 1. So if all x, y, z < 1, then it is the same as the original problem, except we are looking for the minimum this time.

大意就是:

2log, 
x,y,z11,1, 
x,y,z1,,1xyz, 
x,y,z1




cf评论区还有种解法,就是用复数:

D can be solved with complex numbers, to avoid having to treat cases where some numbers are smaller than one, differently. Note that the real part of log(log(x)) is growing if log(log(x)) is real, and decreasing if it has an imaginary part. So you can just write a comparison function to find the maximum.

If x > 1, then log(log(x)) is an increasing function, and if x < 1, then real(log(log(x))) is a decreasing function, because taking a logarithm of a negative number results in something like this: log( - x) = log( - 1·x) = log( - 1) + logx = iπ + log(x). (Assuming log(x) is done in base e) Therefore, to compare two numbers by their loglog, you can do something like this:

bool compare (complex x, complex y) {  if (imag(x) == 0 and imag(y) == 0)     return real(x) > real(y);  else if (imag(x) != 0 and imag(y) == 0)     return false;  else if (imag(x) == 0 and imag(y) != 0)     return true;  else if (imag(x) != 0 and imag(y) != 0)     return real(x) < real(y);}





























































0 0
原创粉丝点击