Codeforces Beta Round #51 B. Smallest number dfs
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 a, b, c, d 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<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std; long long ans = 1LL<<;
char S[];
void solve2(long long a,long long b) {
long long x = (S[] == '+') ? (a + b) : (a * b);
if (ans > x) {
ans = x;
}
}
void solve3(long long a,long long b,long long c) {
if (S[] == '+') {
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[] == '+') {
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=;i<=;i++)
cin>>S[i];
solve4(a,b,c,d);
cout<<ans<<endl;
}
Codeforces Beta Round #51 B. Smallest number dfs的更多相关文章
- Codeforces Beta Round #51 D. Beautiful numbers 数位dp
D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...
- Codeforces Beta Round #51 C. Pie or die 博弈论找规律 有趣的题~
C. Pie or die Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem/ ...
- Codeforces Beta Round #51 A. Flea travel 水题
A. Flea travel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem ...
- Codeforces Beta Round #51 D. Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Beta Round #51 D. Beautiful numbers(数位dp)
题目链接:https://codeforces.com/contest/55/problem/D 题目大意:给你一段区间[l,r],要求这段区间中可以整除自己每一位(除0意外)上的数字的整数个数,例如 ...
- codeforces 55d//Beautiful numbers// Codeforces Beta Round #51
题意:一个数能整除它所有的位上的数字(除了0),统计这样数的个数. 注意离散化,为了速度更快需存入数组查找. 不要每次memset,记录下已有的长度下符合条件的个数. 数位dp肯定是从高位到低位. 记 ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #62 题解【ABCD】
Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
随机推荐
- plsql developer 使用技巧
plsql developer 使用技巧 Oracle数据库相信已成为很多企业构建自身关键业务的重要后台支撑,也是众多开发人员常常采用的后台.但Oracle自己提供的一套客户端工具不是很好用,极大的影 ...
- tcprstat源码分析之tcp数据包分析
tcprstat是percona用来监测mysql响应时间的.不过对于任何运行在TCP协议上的响应时间,都可以用.本文主要做源码分析,如何使用tcprstat请大家查看博文<tcprstat分析 ...
- IOS init initWith 等相关集中
1.initWithCoder 当一个view从nib初始化的时候,会调用这个函数. 用keyedArchiver序列化一个类的实力,后面用keyedUnArchiver拿回来的时候会调用到 ...
- POST 一张 图像的调试来认识 http post
上传图片的详细 2559字节
- 选择学习Pomelo
我之前的项目都是基于http做网络通信,但是做多玩家同时对战的游戏,http短连接不支持服务器的push是个问题,这样客户端就没办法收到服务器的消息. 最简单的方法是定时发起request询问服务器, ...
- MorningSale 使用帮助
待添加 http://121.37.42.173:8080/morningsale
- Canvas入门(3):图像处理和绘制文字
来源:http://www.ido321.com/997.html 一.图像处理(非特别说明,所有结果均来自最新版Google) 在HTML 5中,不仅可以使用Canvas API绘制图形,也可以用于 ...
- 结合Vim ghostscript 将源代码文件转换成语法高亮的pdf格式文档
step 1: 安装ghostscript (debian 环境, 其他环境自行google) sudo apt-get install ghostscript step 2: 用Vim生成ps文件 ...
- Intellij IDEA使用Maven构建Scala项目
1.安装IDEA的Scala插件 使用自带的在线安装方式较为简单.File--Setting--Plugins--Browse reposities 2.创建项目 File - ...
- 《Java数据结构与算法》笔记-CH4-1栈的实现
class StackX{ private int maxSize; private long[] stackArray; private int top; public StackX(int siz ...