题意:把'+', '-', '*' 和'/'按顺序插入任意两数字间隔,使得操作得到后计算后最大。

思路:没想到是个水题,打的时候想得太复杂了。这道题其实只要考虑*和/。显然我们要把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 ;
}

最新文章

  1. [ACM_暴力] ZOJ 3710 [Friends 共同认识 最终认识 暴力]
  2. LeetCode &quot;Minimum Height Tree&quot; !!
  3. php遍历mysql资源
  4. 一个包的TcpServer流程
  5. (转) 各种好用的插件 Xcode
  6. [jQuery] Cannot read property ‘msie’ of undefined错误的解决方法
  7. 在ASP.NET MVC中对手机号码的验证
  8. 【公告】CSDN个人空间将于2014年4月20日全新改版上线
  9. Oracle11g R2学习系列 之十 解决EM不能用
  10. some knowledge
  11. 自己用js写的两个日历控件
  12. php查找字符串是否存在
  13. 通过私有协议Chrome浏览器页面打开本地程序
  14. win7 安装 vagrant + centos + virtualbox
  15. Android Monkey压力测试介绍
  16. 从让 HTTPS 更安全出发,聊聊 HTTPS
  17. TypeError: &#39;NoneType&#39; object is not subscriptable
  18. 洛谷 P3627 [APIO2009]抢掠计划
  19. firstPage
  20. C++学习(二)之Visual Studio写system语句 生成可执行文件

热门文章

  1. Support For C++11/14/17 Features (Modern C++)
  2. Java类访问控制
  3. CNN超参数优化和可视化技巧详解
  4. Sitecore CMS中配置项目图标
  5. Sitecore安装(手动方式)
  6. Java多线程-----线程池详解
  7. JVM调优总结 -Xms
  8. Gibbs Sampling深入理解
  9. 把object转成JSONObject JSON.toJSON
  10. ConvertUtils.register(new DateConverter(null), java.util.Date.class)使用