Four Operations---hdu5938(暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5938
题意:给一个不超过20位并且大于2位的数字字符串(只包含1-9)然后找到适当的位置依次放入"+-*/"四个符号,然后求能构成的最大的数;
可以看成是 A+B-C*D/E这种形式,要想让结果最大,那么A+B要尽可能大,C*D/E要尽可能小;
所以C和D只能是一位数,那么C*D的结果就是1位数或者2位数,因此E取3位数时C*D/E一定是0了,但是这不一定是最大的结果, 所以我们可以枚举E为1,2,3位数时的三种情况, 取最大值;
这样就确定了C,D,E和AB的长度;就可以直接求了;
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = ;
const int INF = 0x3f3f3f3f;
const double eps = 1e-; char s[N];
int len; LL solve(int n)
{
LL Max = ;
for(int i=; i<=n-; i++) ///a由i位数构成;
{
LL a = , b = ;
for(int j=; j<i; j++)
a = a* + s[j]-'';
for(int j=i; j<n; j++)
b = b* + s[j]-'';
Max = max(Max, a+b);
}
return Max;
} LL Find(int k)/// 表示/号后面有k位数;
{
if(len-k < )///要剩下4位以上才可以;
return -INF; LL c, d, e = ;///求 a + b - c*d/e;
for(int i=len-k; i<len; i++)
e = e* + s[i]-''; d = s[len-k-]-'';
c = s[len-k-]-''; LL m = solve(len-k-);///求前面的数能组成的最大的a+b存到m中; return (m-c*d/e);
} int main()
{
int T, t = ;
scanf("%d", &T);
while(T --)
{
scanf("%s", s); len = strlen(s);
LL ans = -INF; ans = max(ans, Find());
ans = max(ans, Find());
ans = max(ans, Find()); printf("Case #%d: %I64d\n", t++, ans);
}
return ;
}
Four Operations---hdu5938(暴力)的更多相关文章
- [HDOJ5938]Four Operations(暴力,DFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5938 题意:给出一个长度最大是2020的数字串, 你要把数字串划分成55段, 依次填入'+', '-' ...
- ACM程序设计选修课——1065: Operations on Grids(暴力字符串)
1065: Operations on Grids Time Limit: 3 Sec Memory Limit: 128 MB Submit: 17 Solved: 4 [Submit][Sta ...
- 开源服务专题之------ssh防止暴力破解及fail2ban的使用方法
15年出现的JAVA反序列化漏洞,另一个是redis配置不当导致机器入侵.只要redis是用root启动的并且未授权的话,就可以通过set方式直接写入一个authorized_keys到系统的/roo ...
- [暴力搜索] POJ 3087 Shuffle'm Up
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10003 Accepted: 4631 Des ...
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort(暴力)
传送门 Description You are given a table consisting of n rows and m columns. Numbers in each row form a ...
- HDU4288:Coder(线段树单点更新版 && 暴力版)
Problem Description In mathematics and computer science, an algorithm describes a set of procedures ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- Codeforces Round #312 (Div. 2) C. Amr and Chemistry 暴力
C. Amr and Chemistry Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/558/ ...
- TZOJ 4325 RMQ with Shifts(线段树查询最小,暴力更新)
描述 In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each que ...
- HDU 6315 Naive Operations(线段树区间整除区间)
Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b i ...
随机推荐
- Linux redirect the stdout to a file
1: int save_out = dup(fileno(stdout));//backup stdout 2: int out = open("cout.log", O_RD ...
- POJ 3352 (边双连通分量)
题目链接: http://poj.org/problem?id=3352 题目大意:一个连通图中,至少添加多少条边,使得删除任意一条边之后,图还是连通的. 解题思路: 首先来看下边双连通分量的定义: ...
- [Algorithms(Princeton)] Week1 - PercolationStats
public class PercolationStats { private int N; private int T; private double[] results; public Perco ...
- Git 的使用感受
Git 的使用感受 从开始工作到现在,在公司里面一直用 svn 来做版本管理.大约半年前听说了 Git,因为 Git 的光辉相当耀眼,作者是 Linus Torvalds,被大量的开源软件采用,如 j ...
- C#输入的字符串只包含汉字
public bool IsAllChineseCh(string input) { Regex regex = new Regex("^[\u4e00 ...
- 将组策略中的内容导出至CSV格式
#将组策略首选项中的"本地用户和组"下的所有条目导出 $xml = Get-GPOReport -ReportType Xml -Name "China Desktop ...
- 对.net系统架构改造的一点经验和教训(转)
在互联网行业,基于Unix/Linux的网站系统架构毫无疑问是当今主流的架构解决方案,这不仅仅是因为Linux本身足够的开放性,更因为围绕传统Unix/Linux社区有大量的成熟开源解决方案,覆盖了网 ...
- HDU 2089 数位dp入门
开始学习数位dp...一道昨天看过代码思想的题今天打了近两个小时..最后还是看了别人的代码找bug...(丢丢) 传说院赛要取消 ? ... 这么菜不出去丢人也好吧~ #include<stdi ...
- hdu1078 记忆化搜索
/* hdu 1078 QAQ记忆化搜索 其实还是搜索..因为里面开了一个数组这样可以省时间 (dp[x][y]大于0就不用算了直接返回值) */ #include<stdio.h> #i ...
- Web 在线文件管理器学习笔记与总结(9)下载文件
① 普通形式的文件可以使用超链接形式下载 <a href = '下载文件名'>点击下载</a> ② 如果下载图片.html 等类型的文件,使用header() 函数发送网页头信 ...