codeforce 621D - Rat Kwesh and Cheese

题意:求表达式中最大的值。

long double 128位 有效数字18-19 范围正负1.2*10^4932

注意取对数!

 1 #include<iostream>
 2 #include<string>
 3 #include<algorithm>
 4 #include<cstdlib>
 5 #include<cstdio>
 6 #include<set>
 7 #include<map>
 8 #include<vector>
 9 #include<cstring>
10 #include<stack>
11 #include<cmath>
12 #include<queue>
13 #include <bits/stdc++.h>
14 using namespace std;
15 #define INF 0x3f3f3f3f
16 #define ll long long
17 #define clc(a,b) memset(a,b,sizeof(a))
18 const int maxn=4010;
19 
20 const char s[12][10]=
21 {
22     "x^y^z",
23     "x^z^y",
24     "(x^y)^z",
25     "(x^z)^y",
26     "y^x^z",
27     "y^z^x",
28     "(y^x)^z",
29     "(y^z)^x",
30     "z^x^y",
31     "z^y^x",
32     "(z^x)^y",
33     "(z^y)^x"
34 };
35 
36 int main()
37 {
38     long double a[12];
39     long double x,y,z;
40     cin>>x>>y>>z;
41     a[0]=pow(y,z)*log(x);
42     a[1]=pow(z,y)*log(x);
43     a[2]=a[3]=y*z*log(x);
44     a[4]=pow(x,z)*log(y);
45     a[5]=pow(z,x)*log(y);
46     a[6]=a[7]=x*z*log(y);
47     a[8]=pow(x,y)*log(z);
48     a[9]=pow(y,x)*log(z);
49     a[10]=a[11]=x*y*log(z);
50     int pos=0;
51     for(int i=1; i<=11; i++)
52     {
53         if(a[i]>a[pos])
54             pos=i;
55     }
56     printf("%s\n",s[pos]);
57     return 0;
58 }
View Code

 

你可能感兴趣的:(codeforce 621D - Rat Kwesh and Cheese)