HDU 5938 Four Operations(乱搞)题解
2024-08-22 01:26:11
题意:把'+', '-', '*' 和'/'按顺序插入任意两数字间隔,使得操作得到后计算后最大。
思路:没想到是个水题,打的时候想得太复杂了。这道题其实只要考虑*和/。显然我们要把a*b/c弄到最小。那么ab只有一位,c可能有两位。m+n-a*b/c最大,那么mn和最大,那么就是-号前面分割最大和。那么就是max(第一位+后面,前面+最后一位)。
代码:
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
typedef long long ll;
const int maxn = + ;
const int seed = ;
const ll MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
char a[];
int num1, num2;
ll pre1, pre2;
bool check(int len){
num1 = (a[len - ] - '') * (a[len - ] - '') / (a[len] - '');
num2 = (a[len - ] - '') * (a[len - ] - '') / ((a[len - ] - '') * + (a[len] - ''));
if(len == ) return false;
if(num1 > num2) return true;
else return false;
}
ll big(int len){
ll num = , Max;
for(int i = ; i <= len - ; i++){
num = num * + (a[i] - '');
}
Max = num + (a[len] - '');
num = ;
for(int i = ; i <= len; i++){
num = num * + (a[i] - '');
}
num += (a[] - '');
Max = max(Max, num);
return Max;
}
int main(){
int T, Case = ;
ll ans;
scanf("%d", &T);
while(T--){
ans = -INF;
scanf("%s", a + );
int len = strlen(a + );
bool two = check(len);
if(two){
ans = big(len - ) - num1;
ans = max(big(len - ) - num2, ans);
}
else{
ans = big(len - ) - num1;
}
printf("Case #%d: %lld\n", Case++, ans);
}
return ;
}
最新文章
- [ACM_暴力] ZOJ 3710 [Friends 共同认识 最终认识 暴力]
- LeetCode ";Minimum Height Tree"; !!
- php遍历mysql资源
- 一个包的TcpServer流程
- (转) 各种好用的插件 Xcode
- [jQuery] Cannot read property ‘msie’ of undefined错误的解决方法
- 在ASP.NET MVC中对手机号码的验证
- 【公告】CSDN个人空间将于2014年4月20日全新改版上线
- Oracle11g R2学习系列 之十 解决EM不能用
- some knowledge
- 自己用js写的两个日历控件
- php查找字符串是否存在
- 通过私有协议Chrome浏览器页面打开本地程序
- win7 安装 vagrant + centos + virtualbox
- Android Monkey压力测试介绍
- 从让 HTTPS 更安全出发,聊聊 HTTPS
- TypeError: &#39;NoneType&#39; object is not subscriptable
- 洛谷 P3627 [APIO2009]抢掠计划
- firstPage
- C++学习(二)之Visual Studio写system语句 生成可执行文件
热门文章
- Support For C++11/14/17 Features (Modern C++)
- Java类访问控制
- CNN超参数优化和可视化技巧详解
- Sitecore CMS中配置项目图标
- Sitecore安装(手动方式)
- Java多线程-----线程池详解
- JVM调优总结 -Xms
- Gibbs Sampling深入理解
- 把object转成JSONObject JSON.toJSON
- ConvertUtils.register(new DateConverter(null), java.util.Date.class)使用