【17.00%】【codeforces 621D】Rat Kwesh and Cheese
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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
【题解】
200^200^200是无法接受的;
考虑取log之后再比较;->高中老师教过的方法我怎么就忘了呢。
然后200^200->1e460左右;但是在long double 前这都不算啥;
long double 最高到10^4932;
所以放心用吧;
另外如果取两次对数会失精度;
一大波WA在等着你;
取对数的时候加加减减小心点;
(或者取两次对数,给的x,y,z比较小的时候直接算.否则取两次对数?->考虑x小于1的时候直接乘,但是0.1 200 200 这样的数据没办法直接算,而两次log精度又不够,所以long double+只取一次log是最好的选择;)
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson L,m,rt<<1
#define rson m+1,R,rt<<1|1
#define LL long long
using namespace std;
//const int MAXN = x;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0);
long double x,y,z;
long double ans[15];
void input_LL(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
}
void input_int(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
}
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
cin>>x>>y>>z;
ans[1] = pow(y,z)*log(x);
ans[2] = pow(z,y)*log(x);
ans[3] = z*y*log(x);
ans[4] = ans[3];
ans[5] = pow(x,z)*log(y);
ans[6] = pow(z,x)*log(y);
ans[7] = x*z*log(y);
ans[8] = ans[7];
ans[9] = pow(x,y)*log(z);
ans[10] = pow(y,x)*log(z);
ans[11] = x*y*log(z);
ans[12] = ans[11];
int j = 1;
for (int i = 2;i <= 12;i++)
if (ans[j]<ans[i])
j = i;
switch (j)
{
case 1:
puts("x^y^z");
break;
case 2:
puts("x^z^y");
break;
case 3:
puts("(x^y)^z");
break;
case 4:
puts("(x^z)^y");
break;
case 5:
puts("y^x^z");
break;
case 6:
puts("y^z^x");
break;
case 7:
puts("(y^x)^z");
break;
case 8:
puts("(y^z)^x");
break;
case 9:
puts("z^x^y");
break;
case 10:
puts("z^y^x");
break;
case 11:
puts("(z^x)^y");
break;
case 12:
puts("(z^y)^x");
break;
}
return 0;
}
【17.00%】【codeforces 621D】Rat Kwesh and Cheese的更多相关文章
- Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese 数学
D. Rat Kwesh and Cheese 题目连接: http://www.codeforces.com/contest/621/problem/D Description Wet Shark ...
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- Codeforces Round #341 Div.2 D. Rat Kwesh and Cheese
嗯本来想着直接算出来不就行了吗 然后我想到了200^200^200....... 好吧其实也不难取两次log就行了 然后我第一次写出来log就写残了........... log里面的拆分要仔细啊.. ...
- codeforce 621D - Rat Kwesh and Cheese
题意:求表达式中最大的值. long double 128位 有效数字18-19 范围正负1.2*10^4932 注意取对数! #include<iostream> #include< ...
- 【24.17%】【codeforces 721D】Maxim and Array
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【50.00%】【codeforces 602C】The Two Routes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【40.17%】【codeforces 569B】Inventory
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【17.07%】【codeforces 583D】Once Again...
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【25.00%】【codeforces 584E】Anton and Ira
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- qemu 参数简介
参数 示例 说明 -hda -hda /data/windows.img 指定windows.img作为硬盘镜像 -cdrom -cdrom /data/windows.iso 指定windows.i ...
- 【例题 6-14 UVA-816】Abbott's Revenge
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 预处理出某个方向的左边.前边.右边是哪个方向就好了. 然后就是普通的bfs了. hash存到某个点,走到这里的方向的最小距离. df ...
- Windows下安装Resin及配置具体解释与公布应用
关于Resin的优点,网上介绍了一大堆.小编经不住诱惑,决定试用一下. 眼下Resin的最新版本号为:4.0.40.能够从官网直接下载. 1. 将下载下来的Resin包解压开,会看到一 ...
- 每日技术总结:Toast组件,eslint,white-space,animate,$emit
1.一个优雅的提示是网站必不可少的. 请参考:vue2.0 自定义 提示框(Toast)组件 2.ESLint使用总结 (1)在.eslintrc.js里关闭某条规则, '规则名': 'off'或0 ...
- lua不同模块调用
一.起因 由于准备把lua加入的系统中,还需把字符串解析json.下了个json的lua,目前还没有搞定.但是一个lua,调用其他lua文件模块,目前刚刚搞定. 暂作记录. 二. 模块调用测试 1. ...
- 【习题 5-10 UVA-1597】Searching the Web
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用map < string,vector < int > >mmap[100];来记录每一个数据段某个字符串 ...
- 【Codeforces Round #439 (Div. 2) C】The Intriguing Obsession
[链接] 链接 [题意] 给你3种颜色的点. 每种颜色分别a,b,c个. 现在让你在这些点之间加边. 使得,同种颜色的点之间,要么不连通,要么连通,且最短路至少为3 边是无向边. 让你输出方案数 [题 ...
- 机器学习算法笔记1_2:分类和逻辑回归(Classification and Logistic regression)
形式: 採用sigmoid函数: g(z)=11+e−z 其导数为g′(z)=(1−g(z))g(z) 如果: 即: 若有m个样本,则似然函数形式是: 对数形式: 採用梯度上升法求其最大值 求导: 更 ...
- Vue源码--解读vue响应式原理
原文链接:https://geniuspeng.github.io/2018/01/05/vue-reactivity/ Vue的官方说明里有深入响应式原理这一节.在此官方也提到过: 当你把一个普通的 ...
- pandas 学习(四)—— 数据处理(清洗)、缺失值的处理
创建 DataFrame: df = pd.DataFrame(np.random.randint(0, 10, (2, 4)), columns=list('ABCD')) 0. 为 data fr ...