Codeforces 621D Rat Kwesh and Cheese【Long Double】
2017-04-19 17:32
381 查看
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:
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
Output
Input
Output
Input
Output
题目大意:
给你12个数,输出最大的那个。
思路:
浮点数范围:
那么对于200^200的数据是可以用long double来存下来的。
所以我们对12个数都取对数,然后再比较大小即可。
如果取两次对数的话,精度损失会很多。
Ac代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
using namespace std;
long double x,y,z;
long double num[50];
char s[15][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()
{
while(cin>>x>>y>>z)
{
long double maxn=-1;
char ans[15];
num[1]=pow(y,z)*log(x);
num[2]=pow(z,y)*log(x);
num[3]=y*z*log(x);
num[4]=y*z*log(x);
num[5]=pow(x,z)*log(y);
num[6]=pow(z,x)*log(y);
num[7]=x*z*log(y);
num[8]=x*z*log(y);
num[9]=pow(x,y)*log(z);
num[10]=pow(y,x)*log(z);
num[11]=x*y*log(z);
num[12]=x*y*log(z);
for(int i=1;i<=12;i++)
{
if(num[i]>maxn)
{
maxn=num[i];
strcpy(ans,s[i]);
}
}
cout<<ans<<endl;
}
}
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:
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
题目大意:
给你12个数,输出最大的那个。
思路:
浮点数范围:
那么对于200^200的数据是可以用long double来存下来的。
所以我们对12个数都取对数,然后再比较大小即可。
如果取两次对数的话,精度损失会很多。
Ac代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
using namespace std;
long double x,y,z;
long double num[50];
char s[15][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()
{
while(cin>>x>>y>>z)
{
long double maxn=-1;
char ans[15];
num[1]=pow(y,z)*log(x);
num[2]=pow(z,y)*log(x);
num[3]=y*z*log(x);
num[4]=y*z*log(x);
num[5]=pow(x,z)*log(y);
num[6]=pow(z,x)*log(y);
num[7]=x*z*log(y);
num[8]=x*z*log(y);
num[9]=pow(x,y)*log(z);
num[10]=pow(y,x)*log(z);
num[11]=x*y*log(z);
num[12]=x*y*log(z);
for(int i=1;i<=12;i++)
{
if(num[i]>maxn)
{
maxn=num[i];
strcpy(ans,s[i]);
}
}
cout<<ans<<endl;
}
}
相关文章推荐
- Codeforces 483B - Friends and Presents(二分)
- Codeforces 196 C. Paint Tree
- codeforces 700C
- Codeforces 762C Two strings 字符串
- Codeforces 808G Anthem of Berland - KMP - 动态规划
- Codeforces Good Bye 2017 - (A,B,C)
- Codeforces 483B Friends and Presents(二分+数论)
- Codeforces 570D Tree Requests 题解&代码
- CodeForces 534B Covered Path
- 算法之路四:codeforces 1A
- CodeForces - 527C Glass Carving(STL)
- CodeForces 152 C.Pocket Book(组合数学)
- Codeforces 128B. String(优先队列,模仿dijkstra求最短路)
- CodeForces 176B - Word Cut 计数DP
- CodeForces 455C Civilization
- Codeforces 551B ZgukistringZ【思维+枚举】
- codeforces 732B Cormen — The Best Friend Of a Man
- codeforces 908d New Year and Arbitrary Arrangement
- Codeforces 484(#276 Div 1) A Bits 乱搞
- CodeForces 163B Lemmings 二分