当前位置:网站首页>Codeforces-479A
Codeforces-479A
2022-07-21 05:04:00 【这一wa是晚安】
A. Expression
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.
Examples
input
1 2 3
output
9
input
2 10 3
output
60
题意:
自己输入三个数字a,b,c你可以使用 * + (),三种自由组合使其得到的运算结果最大。
题解:
就是暴力枚举三个数字由上面三种符号组合的最大值,切忌不要排序,排序,排序(重要的事说三遍),我最开始就是觉得排序将前两个数和与积进行比较然后乘上最大那个数求最大值显然是错误的;
如果你排序对下列样例将过不了:
6
7
1
输出:48
如果你从小到大排序将会得到:49。
代码:
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 250;
int n, m, ans = 0x7f7f7f7f;
int arr[N], brr[N], crr[N];
int a, b, c;
string s;
int main()
{
IOS;
int max1;
cin >> a >> b >> c;
arr[0] = a + b + c;
arr[1] = (a + b) * c;
arr[2] = a + (b * c);
arr[3] = a * b + c;
arr[4] = a * (b + c);
arr[5] = a * b * c;
for (int i = 0; i < 6; i++)
{
max1 = max(max1, arr[i]);
}
cout << max1;
return 0;
}
边栏推荐
猜你喜欢
pycharm专业版创建flask项目|下载flask包|以及一些例子
(笔记)吴恩达深度学习L4W2
Initializing libiomp5. dylib, but found libomp. dylib already initialized
Analyse du principe du Centre de configuration nacos
Nacos注册中心集群数据一致性问题
[3D modeling] SolidWorks 3D modeling and prusaslicer slice printing learning notes
Initializing libiomp5.dylib, but found libomp.dylib already initialized
Nacos-配置中心原理解析
吴恩达深度学习L4W4人脸识别
Esp8266 firmware download and burning (include at firmware download address + firmware burning precautions)
随机推荐
Nacos-注册中心原理解析
n-gram
目标检测任务输出坐标为小数
栈,队列,链表
Solve zsh:command not found
El radio value cannot be echoed
以独占的方式锁定此配置文件失败。另一个正在运行的VMware进程可能正在使用配置文件。
桶排序,冒泡排序,快速排序
conda安装datasets避免冲突命令
UNet复现及环境配置(含数据集)
语义分割、实例分割
OPT101单片光电二极管和单电源互阻放大器使用说明
forms表单验证
【PCB】基於STM32F103RCT6搖杆-藍牙模塊開發板-畫板筆記整理
中文维基语料训练获取
合泰HT32--4SPI驱动0.96英寸OLED显示实现
ES聚合统计语法
Yum install GCC error
pytorch安装
CONDA install datasets to avoid conflicting commands