cf479A Expression

本文探讨如何在三个整数之间插入加号和乘号,以形成表达式并求得最大可能值。

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

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

div2的A啊……sb模拟

六种情况搞来搞去

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
LL a,b,c,ans;
inline LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int main()
{
	a=read();b=read();c=read();
	ans=a+b+c;
	ans=max(ans,a+b*c);
	ans=max(ans,a*b+c);
	ans=max(ans,(a+b)*c);
	ans=max(ans,a*(b+c));
	ans=max(ans,a*b*c);
	printf("%lld\n",ans);
}

2025-04-01 10:44:22.043 TRACE [org.springframework.web.servlet.DispatcherServlet] - GET "/big-screen/get-time-period-traffic?deviceType=3", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet' 2025-04-01 10:44:22.046 TRACE [o.s.w.s.m.m.a.RequestMappingHandlerMapping] - Mapped to com.syzn.dv.biz.bigscreen.northbound.controller.BigScreenController#getTimePeriodTraffic(BigScreenCommonReq) 2025-04-01 10:44:22.075 TRACE [org.springframework.web.method.HandlerMethod] - Arguments: [BigScreenCommonReq(direction=null, deviceType=3, startDate=null, endDate=null)] 2025-04-01 10:44:22.090 DEBUG [org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession 2025-04-01 10:44:22.097 DEBUG [org.mybatis.spring.SqlSessionUtils] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7b1f52cf] was not registered for synchronization because synchronization is not active 2025-04-01 10:44:22.125 DEBUG [org.mybatis.spring.SqlSessionUtils] - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7b1f52cf] 2025-04-01 10:44:22.129 DEBUG [o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver] - Using @ExceptionHandler com.syzn.dv.config.GlobalExceptionHandler#customErrorHandler(RuntimeException) 2025-04-01 10:44:22.129 TRACE [org.springframework.web.method.HandlerMethod] - Arguments: [org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'null != deviceNo and deviceNo.size() > 0'. Cause: org.apache.ibatis.ognl.MethodFailedException: Method "size" failed for object false [java.lang.NoSuchMethodException: java.lang.String.size()]] org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'null != deviceNo and deviceNo.size() > 0'. Cause: org.apache.ibatis.ognl.MethodFailedException: Method "size" failed for object false [java.lang.NoSuchMethodException: java.lang.String.s
最新发布
04-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值