Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese 数学
2016-02-23 22:08
337 查看
D. Rat Kwesh and Cheese
题目连接:
http://www.codeforces.com/contest/621/problem/DDescription
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.Output
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).
Sample Input
1.1 3.4 2.5Sample Output
z^y^xHint
题意
12个表达式,让你输出最大的表达式题解:
这个方法是Hezhu的,Orz太厉害了
我们仔细想一想,次方这个乱七八糟的东西,我们显然可以直接取一个log
但是这个东西还是有200^200,按照题解的方法,你还得取个log,然后再讨论一堆东西
这个太麻烦了
直接上long double就好了,long double 这个东西有自带的powl,logl函数,可以精度更加精确,而且这个玩意儿是存储的科学计数法
总之比较玄学。
最差情况,我想的是,有效数数字就应该只需要16位吧?
代码
#include<bits/stdc++.h> using namespace std; string s[12]={"x^y^z","x^z^y","(x^y)^z","(x^z)^y","y^x^z","y^z^x","(y^x)^z","(y^z)^x","z^x^y","z^y^x","(z^x)^y","(z^y)^x"}; long double d[12]; int main() { long double x,y,z; cin>>x>>y>>z; d[0]=powl(y,z)*logl(x); d[1]=powl(z,y)*logl(x); d[2]=z*y*logl(x); d[3]=z*y*logl(x); d[4]=powl(x,z)*logl(y); d[5]=powl(z,x)*logl(y); d[6]=z*x*logl(y); d[7]=z*x*logl(y); d[8]=powl(x,y)*logl(z); d[9]=powl(y,x)*logl(z); d[10]=x*y*logl(z); d[11]=x*y*logl(z); long double mx = -1e16; int idx = 0; for(int i=0;i<12;i++) if(mx<d[i]) mx=d[i],idx=i; cout<<s[idx]<<endl; }
相关文章推荐
- 伪造http的ip地址,突破ip限制的投票程序
- 【Bootstrap基础学习】05 Bootstrap学习总结
- LongAdder基础
- 《大规模web服务开发技术》笔记
- 58. Length of Last Word
- Linux时间函数之gettimeofday()函数之使用方法
- 每日练习——2016.2.23
- 防止自己网站被拿来钓鱼
- 地图
- hive 学习笔记——表的入门操作和命令
- 高并发高负载系统架构-php篇
- HDU 1686 Oulipo
- 修改支付宝服务窗开发者网关
- 修改url中参数的值
- C/C++: 预处理指令
- 国内开源 java cms,Jspxcms 6.0.1 发布
- 异步复位同步释放的方法以及多时钟系统的复位设计
- 修改url中参数的值
- sequence有关问题
- 知识点小结