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

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


相关推荐

  • 抽象工厂模式与工厂方法模式有哪些不同_抽象工厂模式java代码

    抽象工厂模式与工厂方法模式有哪些不同_抽象工厂模式java代码Abstract Factory动机实例模式定义结构要点总结笔记动机在软件系统中,经常面临着”一系列相互依赖的对象“的创建工作;同时,由于需求的变化,往往存在更多系列对象的创建工作如果应对这种变换?如何绕过常规的对象创建方法(new),提供一种”封装机制“来避免客户程序和这种”多系列具体对象创建工作“的紧耦合?实例数据库连接的时候会有很多关联的对象,这些对象是一个整体朴素class EmployeeDAO{public: vector<EmployeeDAO> GetEm

    2022年8月11日
  • 用flash做古诗动画_《古诗三首》Flash动画课件[通俗易懂]

    用flash做古诗动画_《古诗三首》Flash动画课件[通俗易懂]《古诗三首》Flash动画课件古诗词三首牧童[唐]吕岩草铺横野六七里,笛弄①晚风三四声。归来饱饭黄昏后,不脱蓑衣②卧月明。注释①弄:逗弄。②蓑衣:棕或草编的外衣,用来遮风挡雨。………舟过安仁①[宋]杨万里一叶渔船两小童,收篙②停棹③坐船中。怪生④无雨都张伞,不是遮头是使风。注释①安仁:县名。在湖南省东南部,宋时设县。②篙:撑船用的竹竿或木杆。③棹:船桨。④怪生:怪不得。……

    2022年5月5日
  • linux基本操作命令_vim常用命令

    linux基本操作命令_vim常用命令1.查找文件find/-name*文件名*2.开始、重启、结束进程#开始进程systemctlstartfilebeat#重启systemctlrestartfilebeat#结束systemctlstopfilebeat3.转到目录#从根目录开始搜索文件夹cd/文件名/#从当前目录开始cd文件名/4.编辑文件#编辑vim文件名vi文件名#查看cat文件名5.从编辑状态退出#先按Esc

    2022年9月26日
  • 【原创】记录昨天Oschina上个人博客无法访问的问题

    【原创】记录昨天Oschina上个人博客无法访问的问题

    2021年9月14日
  • Floyed理解「建议收藏」

    Floyed理解「建议收藏」Floyed理解 Floyd算法的本质是动态规划,其转移方程为:f(k,i,j)=min(f(k-1,i,j),f(k-1,i,k)+f(k-1,k,j))。f(k-1,i,j)表示经过前k-1个点f(k-1,i,k)+f(k-1,k,j)表示经过k这个点f(k,i,j)表示路径除开起点i与终点j,只经过前k个点中的某些点,从i到j的最小值。计算这个值只需要考…

    2022年6月29日
  • 计算机-底层-1

    计算机-底层-1

    2021年5月18日

发表回复

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

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