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 ...
随机推荐
- Android 使用库项目时的一个特殊tip
前提: 项目A作为库项目被项目B引用,但是项目A中有自定义的控件和自定义的属性,当在项目B中使用自定义的属性时,编译时就会直接报错:No resource identifier found for a ...
- 解释一下,在你往浏览器中输入一个URL后都发生了什么,要尽可能详细
这道题目没有所谓的完全的正确答案,这个题目可以让你在任意的一个点深入下去, 只要你对这个点是熟悉的.以下是一个大概流程: 浏览器向DNS服务器查找输入URL对应的IP地址. DNS服务器返回网站的IP ...
- System Services -> Memory Management -> About Memory Management
Virtual Address Space Memory Pools Memory Performance Information Virtual Memory Functions Heap Func ...
- java web 学习十二(session)
一.Session简单介绍 在WEB开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占一个session对象(默认情况下).因此,在需要保存用户数据时,服务 ...
- window下版本控制工具Git 客户端安装
安装使用 1.下载msysgit http://code.google.com/p/msysgit/ 2.下载tortoisegit客户端安装 http://code.google.com/p/tor ...
- cocos2d anchor point 锚点解析
anchor point 究竟是怎么回事? 之所以造成不容易理解的是因为我们平时看待一个图片是 以图片的中心点 这一个维度来决定图片的位置的.而在cocos2d中决定一个 图片的位置是由两个维度 一个 ...
- PowerDesigner Vs Enterprise Architect
注: 以下文中PD表示PowerDesigner,EA表示Enterprise Architect 最近一直在做设计方面的事情,之前一直在用PD.有个阿里过来的同事说阿里都是用EA,我就抽空小研究了一 ...
- ASP.NET将word文档转换成pdf的代码
一.添加引用 using Microsoft.Office.Interop.Word; 二.转换方法 1.方法 C# 代码 /// <summary> /// 把Word文件转换成pdf文 ...
- SQL你必须知道的-查询聚合分组排序
use MySchoolTwo -- 简单查询 select * from Student -- 话说这种查询的效率要比 * 要高级点 select sId , sName , ...
- JQuery插件之图片轮播插件–slideBox
来源:http://www.ido321.com/852.html 今天偶然发现了一个比较好用的图片轮播插件—slideBox 先看看效果:http://slidebox.sinaapp.com/ 代 ...