Codeforces621D 高精度 long double + 取log

这题。。。一言难尽
意思是给你 x y z 让你求十二种形式哪个最大
x的y次幂的z次幂啊balabala各种组合
自己刚开始wa到第五组也不知道咋回事 后来发现是最后一组写错了
数据范围0.1~200.0
而且我是取了两次log 网上说精度会有损失
所以long double+一次log是最稳妥的
下面放一下各种浮点数范围
float 32bit -3.410 ^ 38 ~+3.410^38
double 64bit -1.710 ^ -308~1.710^308
long double 128bit/96bit/80bit(不同编译系统不同) -1.210 ^ -4932~1.210^4932
下面是AC代码
还有一点要注意是 log之后最小值不再是0 而是负无穷!!! 所以m初始值不能赋0
要赋值第一个tp!!!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define MID (t[k].l+t[k].r)>>1
#define cl(a,b) memset(a,b,sizeof(a))
#define dbg() printf("aaa\n")
using namespace std;
long double x,y,z;
long double m;
int mul(){
    m=pow(y,z)*log(x);
    int c=1;
    long double tp;
    //2
    tp=pow(z,y)*log(x);
    if(m<tp){m=tp;c=2;}
    //3
    tp=z*y*log(x);
    if(m<tp){m=tp;c=3;}

    //5
    tp=pow(x,z)*log(y);
    if(m<tp){m=tp;c=5;}
    //6
    tp=pow(z,x)*log(y);
    if(m<tp){m=tp;c=6;}
    //7
    tp=x*z*log(y);
    if(m<tp){m=tp;c=7;}

    //9
    tp=pow(x,y)*log(z);
    if(m<tp){m=tp;c=9;}
    //10
    tp=pow(y,x)*log(z);
    if(m<tp){m=tp;c=10;}
    //11
    tp=x*y*log(z);
    if(m<tp){m=tp;c=11;}
    return c;
}
int main() {
	cin>>x>>y>>z;
    switch(mul()){
        case 1: printf("x^y^z\n");break;
        case 2: printf("x^z^y\n");break;
        case 3: printf("(x^y)^z\n");break;
        //case 4: printf("(x^z)^y\n");break;
        case 5: printf("y^x^z\n");break;
        case 6: printf("y^z^x\n");break;
        case 7: printf("(y^x)^z\n");break;
        //case 8: printf("(y^z)^x\n");break;
        case 9: printf("z^x^y\n");break;
        case 10: printf("z^y^x\n");break;
        case 11: printf("(z^x)^y\n");break;
        //case 12: printf("(z^y)^x\n");break;
        default:break;
    }
	return 0;
}

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

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
发布了120 篇原创文章 · 获赞 12 · 访问量 5283

猜你喜欢

转载自blog.csdn.net/weixin_43735161/article/details/104531140