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\n",s[pos]);
    return 0;
}
时间: 2024-10-08 14:13:23

codeforces 621D Rat Kwesh and Cheese的相关文章

Codeforces Round #341 (Div. 2) ABCDE

http://www.cnblogs.com/wenruo/p/5176375.html A. Wet Shark and Odd and Even 题意:输入n个数,选择其中任意个数,使和最大且为奇数. 题解:算出所有数的和,如果奇数的个数为奇数个,则减去最小的奇数,否则不用处理. #include <bits/stdc++.h> using namespace std; #define PI acos(-1.0) #define EXP exp(1.0) #define ESP 1E-6

Codeforces Round #341 (Div. 2)

在家都变的懒惰了,好久没写题解了,补补CF 模拟 A - Wet Shark and Odd and Even #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; const int INF = 0x3f3f3f3f; int main(void) { std::vector<int> vec; int n; scanf ("%d", &n); ll sum = 0;

Codeforces 371BB. Fox Dividing Cheese

Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little be

Codeforces 371C Hamburgers

Description Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down th

CodeForces 586B Laurenty and Shop

F - Laurenty and Shop Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 586B Description A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hu

Codeforces Beta Round #59 (Div. 2)

Codeforces Beta Round #59 (Div. 2) http://codeforces.com/contest/63 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th