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
<think>好的,我现在需要解决用户在MyBatis中遇到的BuilderException异常,具体错误是'null != deviceNo and deviceNo.size() > 0'导致的OGNL MethodFailedException,提示String的size方法异常。首先,我得分析这个问题的原因。 用户的条件判断语句中使用了deviceNo.size(),这说明他们可能希望检查deviceNo是否非空且有元素。但问题在于,如果deviceNo是一个String类型,那么它并没有size()方法,而是有length()方法。MyBatis在解析OGNL表达式时,如果调用不存在的方法,就会抛出这个异常。 接下来,我需要验证这个猜想是否正确。根据引用[3]中的示例,用户在使用String类型时,条件判断是判断是否为null,比如cityName != null。而如果deviceNo是String类型,正确的判断应该是检查其长度是否大于0,使用deviceNo.length() > 0或者更简洁的deviceNo != null and deviceNo != ''。 另外,如果用户误将deviceNo当作集合处理,比如List或数组,那么确实应该使用size()方法。这时候需要确认deviceNo的实际类型是什么。如果是集合类型,那么检查是否为null以及size()是否正确;如果是String,则应该使用length()或者直接判断非空和非空字符串。 解决方案应该包括两个方向:如果deviceNo是String类型,修改表达式为null != deviceNo and deviceNo.length() > 0;或者使用MyBatis内置的_parameter来避免空指针,例如使用<if test="deviceNo != null and deviceNo != ''">。此外,还可以用@Param注解明确参数名称,确保OGNL能正确解析。 最后,提醒用户注意参数类型与方法匹配,避免类似错误。需要确保他们在条件判断中使用的方法与实际类型一致,比如字符串用length(),集合用size(),数组用length等。同时,参考引用[1]中的类型处理,确保MyBatis正确映射属性类型,避免因类型不匹配导致的异常。</think>### MyBatis中表达式`null != deviceNo and deviceNo.size() > 0`的异常解决方案 #### 问题分析 该异常通常由以下原因导致: 1. **OGNL表达式语法错误**:`deviceNo`是字符串类型(String),而`size()`方法是针对集合(如List、Map)的方法,字符串应使用`length()`方法[^3]。 2. **空指针风险**:未对`deviceNo`进行非空判断直接调用方法,若`deviceNo`为`null`会触发空指针异常。 3. **参数类型不匹配**:MyBatis可能未能正确推断参数类型,导致方法调用失败[^1]。 --- #### 解决方案 分步解决如下: 1. **修正方法名** 若`deviceNo`是字符串类型,应将`size()`替换为`length()`: ```xml <if test="null != deviceNo and deviceNo.length() > 0"> ``` 2. **简化非空判断** 直接利用MyBatis的隐式空值检查: ```xml <if test="deviceNo != null and deviceNo != ''"> ``` 3. **使用`_parameter`避免空指针** 若参数是简单类型或未明确命名,可通过`_parameter`引用参数: ```xml <if test="_parameter != null and _parameter.deviceNo != null and _parameter.deviceNo.length() > 0"> ``` 4. **明确参数类型** 在Mapper接口中通过`@Param`注解指定参数名和类型: ```java List<Device> queryDevices(@Param("deviceNo") String deviceNo); ``` --- #### 示例代码 ```xml <!-- 修正后的SQL片段 --> <select id="queryDevices" resultType="Device"> SELECT * FROM devices WHERE 1=1 <if test="deviceNo != null and deviceNo != ''"> AND device_no = #{deviceNo} </if> </select> ``` --- #### 扩展说明 - **OGNL表达式规则**:MyBatis使用OGNL解析表达式,需确保方法与参数类型严格匹配。例如: - 集合类型:`list.size() > 0` - 字符串类型:`str != null and str.length() > 0` - 数组类型:`array.length > 0` - **类型推断机制**:MyBatis通过`ofType`和`javaType`属性处理复杂类型嵌套[^1],需确保XML配置与Java类型一致。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值