zoukankan      html  css  js  c++  java
  • codeforces 621D Rat Kwesh and Cheese

    D. Rat Kwesh and Cheese

     

    Wet Shark asked Rat Kwesh to generate three positive real numbers xy 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 xy 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 xy and z (0.1 ≤ x, y, z ≤ 200.0). Each of xy and z is given with exactly one digit after the decimal point.

    Output

    Find the maximum value of expression among xyzxzy(xy)z(xz)yyxzyzx(yx)z(yz)xzxyzyx(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 test(s)
    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

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    const char s[12][10]=
    {
        "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()
    {
        long double a[12];
        long double x,y,z;
        cin>>x>>y>>z;
        a[0]=pow(y,z)*log(x);
        a[1]=pow(z,y)*log(x);
        a[2]=a[3]=y*z*log(x);
        a[4]=pow(x,z)*log(y);
        a[5]=pow(z,x)*log(y);
        a[6]=a[7]=x*z*log(y);
        a[8]=pow(x,y)*log(z);
        a[9]=pow(y,x)*log(z);
        a[10]=a[11]=x*y*log(z);
        int pos=0;
        for(int i=1;i<12;i++)
            if(a[i]>a[pos])pos=i;
        printf("%s
    ",s[pos]);
        return 0;
    }
  • 相关阅读:
    iOS 微信支付SDK与微信友盟分享两者同时集成时,出现的问题与解决之路。
    Object-C语言Block的实现方式
    使用Mac命令别名,提升工作效率
    利用OC对象的消息重定向forwardingTargetForSelector方法构建高扩展性的滤镜功能
    渐变色进度条的两种绘制方案
    设计模式应用场景之Model设计中可以用到的设计模式
    有趣的赫夫曼树
    技术团队管理者的问题视角
    SSH安全登陆原理:密码登陆与公钥登陆
    为什么HashMap继承了AbstractMap还要实现Map?
  • 原文地址:https://www.cnblogs.com/homura/p/5176297.html
Copyright © 2011-2022 走看看