Codeforces Round #274 (Div. 2) –A Expression

Codeforces Round #274 (Div. 2) –A Expression

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

主题链接: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 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

大致题意: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.net/117058.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 详解Linux双网卡绑定之bond0「建议收藏」

    1、什么是bond?  网卡bond是通过多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在生产场景中是一种常用的技术。Kernels2.4.12及以后的版本均供bonding模块,以前的版本可以通过patch实现。2、实现原理:  网卡工作在混杂(promisc)模式,接收到达网卡的所有数据包,tcpdump工作用的也是混杂模式(promisc),将两块网卡的MAC地址…

    2022年4月1日
    63
  • Android中的跨进程通信方法实例及特点分析(二):ContentProvider

    Android中的跨进程通信方法实例及特点分析(二):ContentProvider

    2022年1月22日
    42
  • Fibers_fiber bundle

    Fibers_fiber bundle要理解Fibers首先需要对抢占式多任务和协作式多任务有所了解抢占式多任务抢占式是指暂停或中断正在执行的计算任务,而不是与其合作。中断后再继续恢复该任务的执行,这种改变又称为上下文切换。其缺点在于操作系统可能会在一个不适当的时间进行上下文切换。例如:Linux的调度程序特权任务Scheduler采用的就是取消进程任务,而不是与其合作。协作式多任务早期的多任务处理系…

    2022年10月22日
    0
  • 排队论[通俗易懂]

    排队论[通俗易懂]排队论简介历史排队论又称随机服务系统,是研究系统随机聚散现象和随机服务系统工作过程的数学理论和方法,是运筹学的一个分支。排队论的基本思想是1909年丹麦数学家A.K.埃尔朗在解决自动

    2022年8月5日
    3
  • [Unity面试] 2022年Unity面试题分享「建议收藏」

    [Unity面试] 2022年Unity面试题分享「建议收藏」2022Unity面试题分享建议收藏

    2022年10月5日
    0
  • Rabbitmq启动方式

    Rabbitmq启动方式Rabbitmq启动方式1以应用方式启动rabbitmq-server-detached后台启动Rabbitmq-server直接启动,如果你关闭窗口或者需要在改窗口使用其他命令时应用就会停止关闭:rabbitmqctlstop2、以服务方式启动(安装完之后在任务管理器中服务一栏能看到RabbtiMq)rabbitmq-serviceinstall安装服务…

    2025年8月1日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号