Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese

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 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:

  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 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).

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

【题意】给定公式求值最大中下标最小的公式

【分析】考虑取一个对数的话,值就算用double也是不够的,要用long double。然后将对应的公式取对数就行了。取pow的时候需要使用powl,这是long double版本的pow函数。然后这道题还有一种解法,直接用复数,可以见blog:http://blog.csdn.net/lwt36/article/details/50618702

【AC 代码】

#include <bits/stdc++.h>
using namespace std;
long double a[15];
long double x,y,z;
const long double eps = 1e-8;
char ans[12][15]={"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"};
int main()
{
    cin>>x>>y>>z;
    long double logx = log(x);
    long double logy = log(y);
    long double logz = log(z);
    a[0] = powl(y,z)*logx;
    a[1] = powl(z,y)*logx;
    a[2] = y*z*logx;
    a[3] = -1;
    a[4] = powl(x,z)*logy;
    a[5] = powl(z,x)*logy;
    a[6] = x*z*logy;
    a[7] = -1;
    a[8] = powl(x,y)*logz;
    a[9] = powl(y,x)*logz;
    a[10] = x*y*logz;
    a[11] = -1;
    long double anss=a[0];
    int idx=0;
    for(int i=1; i<12; i++){
        if(!fabs(anss-a[i])<eps&&a[i]>anss){
            anss = a[i];
            idx = i;
        }
    }
    printf("%s\n",ans[idx]);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值