Codeforces Round #341 (Div. 2) Editorial D - Rat Kwesh and Cheese(数学,高精度)
来源:互联网 发布:java join 编辑:程序博客网 时间:2024/06/08 12:18
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.
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.
Find 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).
1.1 3.4 2.5
z^y^x
2.0 2.0 2.0
x^y^z
1.9 1.8 1.7
(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.
大意就是:
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);}
- Codeforces Round #341 (Div. 2) Editorial D - Rat Kwesh and Cheese(数学,高精度)
- Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese
- Codeforces Round #341 (Div. 2)D. Rat Kwesh and Cheese
- Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese
- Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese(数学 | 复数)
- Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese (pow,复数
- Codeforces 621 D Rat Kwesh and Cheese
- 【17.00%】【codeforces 621D】Rat Kwesh and Cheese
- Codeforces 621D Rat Kwesh and Cheese【Long Double】
- CodeForces 621 D.Rat Kwesh and Cheese(水~)
- Codeforces #341 D. Rat Kwesh and Cheese 浮点数处理技巧 好题
- CF621D - Rat Kwesh and Cheese
- codeforce341 D题 Rat Kwesh and Cheese(复数)
- Codeforces Round #353 (Div. 2) Editorial
- Codeforces Round #357 (Div. 2) Editorial
- Editorial Divide by Zero and Codeforces Round #399 (Div. 1+2, combined) (A~F)
- Codeforces Round #419 (Div. 2) (Codeforces 815B) D. Karen and Test 组合数学
- Codeforces Round #253 (Div. 2) D. Andrey and Problem (贪心+数学概率)
- 【C++】【USACO1.1.2】贪婪的送礼者
- 键盘事件
- activiti,工作流,web流程设计器,SSM,activiti工作流
- 【HTML & CSS & JavaScript】overflow属性滚动机制
- vivado笔记
- Codeforces Round #341 (Div. 2) Editorial D - Rat Kwesh and Cheese(数学,高精度)
- Unity3d Update和FixedUpdate、LateUpdate的区别
- java网站源码 模版 springmvc SSM freemaker
- GitHub常用操作
- MVC 、MVP 、MVVM的讲解
- 【C++】【USACO1.1.3】黑色星期五
- 最小生成树 Kruskal&&Prim
- 普通用户用su 切换root,提示:“incorrect password!”
- Bower : ENOGIT git is not installed or not in the path