主题链接: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原创文章。转载本文,请添加链接^_^

Codeforces Round #274 (Div. 2) --A Expression的更多相关文章

  1. codeforces水题100道 第八题 Codeforces Round #274 (Div. 2) A. Expression (math)

    题目链接:http://www.codeforces.com/problemset/problem/479/A题意:给你三个数a,b,c,使用+,*,()使得表达式的值最大.C++代码: #inclu ...

  2. Codeforces Round #274 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/479 这次自己又仅仅能做出4道题来. A题:Expression 水题. 枚举六种情况求最大值就可以. 代码例如以下: #inc ...

  3. Codeforces Round #274 (Div. 2)

    A http://codeforces.com/contest/479/problem/A 枚举情况 #include<cstdio> #include<algorithm> ...

  4. Codeforces Round #274 (Div. 1) C. Riding in a Lift 前缀和优化dp

    C. Riding in a Lift Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/pr ...

  5. Codeforces Round #274 (Div. 1) B. Long Jumps 数学

    B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/ ...

  6. Codeforces Round #274 (Div. 1) A. Exams 贪心

    A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...

  7. Codeforces Round #274 (Div. 2)-C. Exams

    http://codeforces.com/contest/479/problem/C C. Exams time limit per test 1 second memory limit per t ...

  8. Codeforces Round #274 Div.1 C Riding in a Lift --DP

    题意:给定n个楼层,初始在a层,b层不可停留,每次选一个楼层x,当|x-now| < |x-b| 且 x != now 时可达(now表示当前位置),此时记录下x到序列中,走k步,最后问有多少种 ...

  9. Codeforces Round #274 (Div. 2) E. Riding in a Lift(DP)

    Imagine that you are in a building that has exactly n floors. You can move between the floors in a l ...

随机推荐

  1. 【c语言】模拟库函数strstr

    // 模拟库函数strstr #include <stdio.h> #include <assert.h> const char* my_strstr(const char * ...

  2. HTML5 CSS3专题 纯CSS打造相冊效果

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/30993277 今天偶然发现电脑里面还有这种一个样例.感觉效果还不错,不记得啥时候 ...

  3. php-GD库的函数(二)

    <?php //imagecopy — 拷贝图像的一部分粘贴到某图像上 /*bool imagecopy ( resource $dst_im , resource $src_im , int ...

  4. Beginning Python From Novice to Professional (4) - 演示样本格式字符串

    $ gedit price.py #!/usr/bin/env python width = input('Please enter width: ') price_width = 10 item_w ...

  5. CentOS 6.5安全加固及性能优化

    (文章来自:http://www.cnblogs.com/seasonzone/p/3526296.html) 我们可以通过调整系统参数来提高系统内存.CPU.内核资源的占用,通过禁用不必要的服务.端 ...

  6. 【spring源代码分析】--Bean的解析与注冊

    接着上一节继续分析,DefaultBeanDefinitionDocumentReader的parseBeanDefinitions方法: protected void parseBeanDefini ...

  7. 从零開始学习OpenCL开发(一)架构

    多谢大家关注 转载本文请注明:http://blog.csdn.net/leonwei/article/details/8880012 本文将作为我<从零開始做OpenCL开发>系列文章的 ...

  8. AndroidUI组件之ListView小技巧

    android:fadingEdge="none"//出去黑影  android:listSelector="@android:color/transparent&quo ...

  9. Effective C++:规定20: 宁pass-by-reference-to-const更换pass-by-value

    (一) 假设传递参数当函数被调用pass-by-value,然后函数的参数是基于实际参数的副本最初值,调用,也得到该函数返回的结束值复印件. 请看下面的代码: class Person { publi ...

  10. C++习题 复数类--重载运算符+

    Description 定义一个复数类Complex,重载运算符"+",使之能用于复数的加法运算.将运算符函数重载为非成员.非友元的普通函数.编写程序,求两个复数之和. Input ...