Wet Shark asked Rat Kwesh to generate three positive real numbers x, y 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 x, y and z to Rat Kwesh, and Rat Kwesh will pick one of the these twelve options:
a1 = xyz; a2 = xzy; a3 = (xy)z; a4 = (xz)y; a5 = yxz; a6 = yzx; a7 = (yx)z; a8 = (yz)x; a9 = zxy; a10 = zyx; a11 = (zx)y; 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 x, y and z (0.1 ≤ x, y, z ≤ 200.0). Each of x, y and z is given with exactly one digit after the decimal point.
OutputFind the maximum value of expression among xyz, xzy, (xy)z, (xz)y, yxz, yzx, (yx)z, (yz)x, zxy, zyx, (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.1≤x,y,z≤200.0,给出12种x,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.
大意就是:取2次log,分两种情况 一种是x,y,z至少有1个大于1,显然只有大于1的可以做底数,然后比大 一种是x,y,z全都小于等于1,把其中一个取倒数,然后变成了1xyz,然后比分母比小 x,y,z有等于1的要特判。。 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); }
