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

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 a, b, c 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 a, b and c print the maximum value that you can get.

Input

The input contains three integers a, b 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种运算方式——
*(+)
(+)*
我们枚举所有的运算方式,更新最大值即可。

*/

你可能感兴趣的:(水题,codeforces,暴力,题库-CF)