博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Beta Round #51 B. Smallest number dfs
阅读量:7098 次
发布时间:2019-06-28

本文共 2619 字,大约阅读时间需要 8 分钟。

B. Smallest number

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/55/problem/B

Description

Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers abcd on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations.

Input

First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication)

Output

Output one integer number — the minimal result which can be obtained.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).

Sample Input

1 1 1 1 + + *

Sample Output

3

HINT

 

题意

给你4个数,然后给你三个符号,问你怎么安排着4个数的顺序,可以使得最后的答案最小

4个数和三个符号,选两个数和第一个符号出来,得到一个数

3个数和2个符号,选两个数和第二个符号出来,得到一个数

2个数和1个符号,得到答案

要求使得答案最小

题解:

暴力枚举。。。

代码:

#include
#include
#include
#include
using namespace std;long long ans = 1LL<<61;char S[10];void solve2(long long a,long long b) { long long x = (S[4] == '+') ? (a + b) : (a * b); if (ans > x) { ans = x; }}void solve3(long long a,long long b,long long c) { if (S[3] == '+') { solve2(a + b, c); solve2(a + c, b); solve2(b + c, a); } else { solve2(a * b, c); solve2(a * c, b); solve2(b * c, a); }}void solve4(long long a,long long b,long long c,long long d) { if (S[2] == '+') { solve3(a + b, c, d); solve3(a + c, b, d); solve3(a + d, b, c); solve3(b + c, a, d); solve3(b + d, a, c); solve3(c + d, a, b); } else { solve3(a * b, c, d); solve3(a * c, b, d); solve3(a * d, b, c); solve3(b * c, a, d); solve3(b * d, a, c); solve3(c * d, a, b); }}int main() { long long a, b, c, d; cin>>a>>b>>c>>d; for(int i=2;i<=4;i++) cin>>S[i]; solve4(a,b,c,d); cout<
<

 

转载地址:http://rchql.baihongyu.com/

你可能感兴趣的文章
_DataStructure_C_Impl:链串
查看>>
openvas
查看>>
SecureCRT同时向多个终端发送命令
查看>>
【IntelliJ】IntelliJ IDEA常用设置及快捷键以及自定义Live templates
查看>>
indexOf 和 lastIndexOf 的区别
查看>>
spring boot整合activemq消息中间件
查看>>
Spark:java api实现word count统计
查看>>
mqtt-jmeter
查看>>
PyTorch保存模型与加载模型+Finetune预训练模型使用
查看>>
js 获取当前日期时间 格式为 yyyy-mm-dd hh:MM:ss
查看>>
解决TextBox中, JS方法(DatePicker)改变Text内容后, 无法触发OnTextChanged事件的问题
查看>>
什么是lua?
查看>>
JSON与JAVA数据的转换
查看>>
装饰模式(Decorator Pattern)--结构型
查看>>
Winform动态显示图片,数据流方式
查看>>
Android上的蓝牙通信功能的开发:BluetoothChat例程分析
查看>>
POJ 2244
查看>>
IOS各种文件描述
查看>>
Eclipse快捷键大全(转载)
查看>>
Yahoo!网站性能最佳体验的34条黄金守则——图片、Coockie与移动应用
查看>>