codeforce 621D - Rat Kwesh and Cheese

本文介绍了一种算法,用于求解包含三个变量x、y、z的不同组合形式的指数运算表达式中的最大值。通过预计算每种可能的表达式形式并比较其对数值来确定最大值对应的表达式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

 

转载于:https://www.cnblogs.com/ITUPC/p/5178492.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值