【Codeforces Round 274 (Div 2)A】【暴力 水题】Expression 三个数值运算使得结果最大

99 篇文章 0 订阅
55 篇文章 0 订阅
A. Expression
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers abc on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:

  • 1+2*3=7
  • 1*(2+3)=5
  • 1*2*3=6
  • (1+2)*3=9

Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.

It's easy to see that the maximum value that you can obtain is 9.

Your task is: given ab and c print the maximum value that you can get.

Input

The input contains three integers ab and c, each on a single line (1 ≤ a, b, c ≤ 10).

Output

Print the maximum value of the expression that you can obtain.

Sample test(s)
input
1
2
3
output
9
input
2
10
3
output
60

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
int a,b,c;
int main()
{
	while(~scanf("%d%d%d",&a,&b,&c))
	{
		int ans=0;
		gmax(ans,a+b+c);
		gmax(ans,a*b*c);
		gmax(ans,(a+b)*c);
		gmax(ans,a*(b+c));
		gmax(ans,a+b*c);
		gmax(ans,a*b+c);
		printf("%d\n",ans);
	}
	return 0;
}
/*
【trick&&吐槽】
水题如果写错变量,很伤,非常伤,血崩!

【题意】
给你三个数a,b,c,数值在[1,10]之间。
三个数之间可以任意加括号,以及加两个运算符号(任选+或*),使得最后运算的结果尽可能大。
让你输出这个最大结果

【类型】
暴力 水题

【分析】
如果不加括号,只有4种运算方式,
+ +
* *
+ *
* +
如果加括号,也不过多了2种运算方式——
*(+)
(+)*
我们枚举所有的运算方式,更新最大值即可。

*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值