当前位置:网站首页>Codeforces Round #274 (Div. 2) –A Expression
Codeforces Round #274 (Div. 2) –A Expression
2022-07-06 13:45:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
主题链接:Expression
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
大致题意:a, b, c三个数。在三个数中,插入“+” 和“*”运算符的随意两个组合,求能组成的表达式的值得最大值。(能够用括号)
解题思路:没啥说的。直接暴力,总共就6种组合。
AC代码:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define INF 0x7fffffff
int x[9];
int main()
{
// #ifdef sxk
// freopen("in.txt","r",stdin);
// #endif
int a,b,c;
while(scanf("%d%d%d",&a,&b,&c)!=EOF)
{
x[0] = a + b + c;
x[1] = a + (b * c);
x[2] = a * (b + c);
x[3] = (a + b) * c;
x[4] = (a * b) + c;
x[5] = a * b * c;
sort(x, x+6);
printf("%d\n",x[5]);
}
return 0;
}
版权声明:本文sxk原创文章。转载本文,请添加链接^_^
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117058.html原文链接:https://javaforall.cn
边栏推荐
- 50个常用的Numpy函数解释,参数和使用示例
- Absolute primes (C language)
- Univariate cubic equation - relationship between root and coefficient
- Earned value management EVM detailed explanation and application, example explanation
- mysql根据两个字段去重
- b站视频链接快速获取
- Fastjson parses JSON strings (deserialized to list, map)
- [Yu Yue education] reference materials for surgical skills teaching in Tongji University
- 50 commonly used numpy function explanations, parameters and usage examples
- Description of web function test
猜你喜欢
[Chongqing Guangdong education] Information Literacy of Sichuan Normal University: a new engine for efficiency improvement and lifelong learning reference materials
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
It's not my boast. You haven't used this fairy idea plug-in!
Happy sound 2[sing.2]
Checkpoint of RDD in spark
Leetcode learning records (starting from the novice village, you can't kill out of the novice Village) ---1
Reptile practice (V): climbing watercress top250
基于LM317的可调直流电源
跨分片方案 总结
20 large visual screens that are highly praised by the boss, with source code templates!
随机推荐
设置状态栏样式Demo
Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
Sdl2 source analysis 7: performance (sdl_renderpresent())
Binary tree node at the longest distance
[Li Kou brush questions] 32 Longest valid bracket
跨分片方案 总结
Reinforcement learning - learning notes 5 | alphago
在Pi和Jetson nano上运行深度网络,程序被Killed
【MySQL】Online DDL详解
Shake Sound poussera l'application indépendante de plantation d'herbe "louable", les octets ne peuvent pas oublier le petit livre rouge?
Intelligent online customer service system source code Gofly development log - 2 Develop command line applications
Earned value management EVM detailed explanation and application, example explanation
美国科技行业结束黄金时代,芯片求售、裁员3万等哀声不断
ROS error: could not find a package configuration file provided by "move_base“
Michael smashed the minority milk sign
MySQL - transaction details
One line by line explanation of the source code of anchor free series network yolox (a total of ten articles, you can change the network at will after reading it, if you won't complain to me)
在最长的距离二叉树结点
Technology sharing | packet capturing analysis TCP protocol
string的底层实现