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 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 xyz (without brackets), and (xy)z should be outputted as (xy)z (quotes for clarity).
Sample Input
1.1 3.4 2.5
Sample Output
zyx
Hint
题意
12个表达式,让你输出最大的表达式
题解:
这个方法是Hezhu的,Orz
太厉害了
我们仔细想一想,次方这个乱七八糟的东西,我们显然可以直接取一个log
但是这个东西还是有200^200,按照题解的方法,你还得取个log,然后再讨论一堆东西
这个太麻烦了
直接上long double就好了,long double 这个东西有自带的powl,logl函数,可以精度更加精确,而且这个玩意儿是存储的科学计数法
总之比较玄学。
最差情况,我想的是,有效数数字就应该只需要16位吧?
代码
#include<bits/stdc++.h>
using namespace std;
string s[12]={"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"};
long double d[12];
int main()
{
long double x,y,z;
cin>>x>>y>>z;
d[0]=powl(y,z)*logl(x);
d[1]=powl(z,y)*logl(x);
d[2]=z*y*logl(x);
d[3]=z*y*logl(x);
d[4]=powl(x,z)*logl(y);
d[5]=powl(z,x)*logl(y);
d[6]=z*x*logl(y);
d[7]=z*x*logl(y);
d[8]=powl(x,y)*logl(z);
d[9]=powl(y,x)*logl(z);
d[10]=x*y*logl(z);
d[11]=x*y*logl(z);
long double mx = -1e16;
int idx = 0;
for(int i=0;i<12;i++)
if(mx<d[i])
mx=d[i],idx=i;
cout<<s[idx]<<endl;
}
Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese 数学的更多相关文章
- Codeforces Round #341 Div.2 D. Rat Kwesh and Cheese
嗯本来想着直接算出来不就行了吗 然后我想到了200^200^200....... 好吧其实也不难取两次log就行了 然后我第一次写出来log就写残了........... log里面的拆分要仔细啊.. ...
- Codeforces Round #341 (Div. 2)
在家都变的懒惰了,好久没写题解了,补补CF 模拟 A - Wet Shark and Odd and Even #include <bits/stdc++.h> typedef long ...
- Codeforces Round #341 (Div. 2) ABCDE
http://www.cnblogs.com/wenruo/p/5176375.html A. Wet Shark and Odd and Even 题意:输入n个数,选择其中任意个数,使和最大且为奇 ...
- Codeforces Round #341 (Div. 2) E. Wet Shark and Blocks dp+矩阵加速
题目链接: http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test2 se ...
- Codeforces Round #341 Div.2 C. Wet Shark and Flowers
题意: 不概括了..太长了.. 额第一次做这种问题 算是概率dp吗? 保存前缀项中第一个和最后一个的概率 然后每添加新的一项 就解除前缀和第一项和最后一项的关系 并添加新的一项和保存的两项的关系 这里 ...
- Codeforces Round #341 Div.2 B. Wet Shark and Bishops
题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数 由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y 然后每个数组中扫描重复数字k ans加上kC ...
- Codeforces Round #341 Div.2 A. Wet Shark and Odd and Even
题意是得到最大的偶数和 解决办法很简单 排个序 取和 如果是奇数就减去最小的奇数 #include <cstdio> #include <cmath> #include < ...
- Codeforces Round #341 (Div. 2) E - Wet Shark and Blocks
题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k< ...
- Codeforces Round #341 (Div. 2) C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
随机推荐
- Perl6 Bailador框架(1):开始
use v6; use Bailador; get '/' => sub { '<h1><center>Hello, World</center></h ...
- Python模块学习 - Functools
Functools模块 Higher-order functions and operations on callable objects,看这个标题我都是懵逼的,这都是啥啥啥啊,赶紧拿出百度翻译:可 ...
- linux中断线程化分析【转】
转自:http://blog.csdn.net/qq405180763/article/details/24120895 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近在为3.8版本的Li ...
- 安全测试===sqlmap(贰)转载
十二.列举数据 这些参数用于列举出数据库管理系统信息.数据结构和数据内容. 1.一键列举全部数据 参数:--all 使用这一个参数就能列举所有可访问的数据.但不推荐使用,因为这会发送大量请求,把有用和 ...
- (二十一)Makefile例子
ROOT_PROJECT = .DIR_INC = -I$(ROOT_PROJECT)/include -I$(ROOT_PROJECT)/include/NE10 DIR_BIN = $(ROOT_ ...
- ExecutorService 用例
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Tes ...
- ES6的新增数据类型:Symbol
简介:Symbol类型是es6新增的一个数据类型,Es5的基本数据类型(undefined,null,Object,function,Number,string) Symbol值通过Symbol函数生 ...
- 常用SQL时间格式SQLServer中文版的默认的日期字段datetime格式是yyyy-mm-d
常用SQL时间格式 SQL Server中文版的默认的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm 例如: select getdate() -- ::08.177 ...
- golang实现mysql数据库备份
背景 navicat是mysql可视化工具中最棒的,但是,在处理视图的导入导出方面,它是按照视图名称的字母顺序来处理的,若视图存在依赖,在导入过程中就会报错.前面已经用python写了一个,但在使用过 ...
- Centos7使用squid实现正向代理
正向代理:代理服务器帮助客户端(浏览器)实现互联网的访问 (1)代理服务器配置 1.安装squid yum install squid -y 2.编辑squid配置文件 #vim /etc/squid ...