Four Operations HDU
来源:互联网 发布:java随机生成汉字名字 编辑:程序博客网 时间:2024/06/05 20:41
题目:https://vjudge.net/contest/191379#problem/F
题目大意
将一串数字按顺序划分,满足公式 A+B-C*D/E, 求划分所得公式的值最大是多少
分析
- 首先可以明确,要想值最大,那么 C*D/E 就要尽可能的小。
- 容易想到 C*D/E 最小为0, 那么C*D应尽可能的小,E尽可能的大。
- 对于 A+B 来说,要最大就必须保证位数最大,那么有两种情况,要么A占前一位 ,B占剩余位,要么B占最后一位,A占剩余位。
以上条件,我们可以通过枚举减号的位置来确定最终的最大值,实际上还是策略性的暴力解题。
代码
/******************************************************************** * File Name: F.cpp * Author: Sequin * mail: Catherine199787@outlook.com * Created Time: 一 10/23 18:18:18 2017 *************************************************************************/#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <ctype.h>#include <set>#include <vector>#include <cmath>#include <bitset>#include <algorithm>#include <climits>#include <string>#include <list>#include <cctype>#include <cstdlib>#include <fstream>#include <sstream>using namespace std;#define lson 2*i#define rson 2*i+1#define LS l,mid,lson#define RS mid+1,r,rson#define UP(i,x,y) for(i=x;i<=y;i++)#define DOWN(i,x,y) for(i=x;i>=y;i--)#define MEM(a,x) memset(a,x,sizeof(a))#define W(a) while(a)#define gcd(a,b) __gcd(a,b)#define pi acos(-1.0)#define pii pair<ll,ll>#define ll long long#define MAX 10000005#define MOD 1000000007#define INF 0x3f3f3f3f#define EXP 1e-8#define lowbit(x) (x&-x)ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}ll num[1003];ll make(ll x, ll y) { ll ret = 0; while(x < y) { ret = ret * 10 + num[x++]; } return ret;}int main() { ios::sync_with_stdio(false); ll T, t; cin >> T; UP(t, 1, T) { memset(num, 0, sizeof(num)); ll ans = -INF; string str; cin >> str; for(ll i = 1; i <= str.length(); i++) { num[i] = str[i-1] - '0'; } for(ll i = 3; i + 2<= str.length(); i++) { ll ab = 0; ab = max(ab, make(1, i-1) + num[i-1]); ab = max(ab, num[1] + make(2, i)); ll e = 0; for(ll j = i+2; j <= str.length(); j++) { e = max(e, make(j, str.length()+1)); } //cout << ab << " " << e << endl; ans = max(ans, ab - num[i] * num[i+1] / e); } cout << "Case #" << t << ": " << ans << endl; } return 0;}
阅读全文
0 0
- HDU 5938 Four Operations
- hdu 5938 Four Operations
- hdu 5938 Four Operations
- Four Operations HDU
- hdu 5938 Four Operations【贪心】
- hdu 5938 Four Operations 模拟
- HDU 5938 Four Operations 贪心
- HDU 5938 Four Operations 模拟
- HDU 5938 Four Operations(思维)
- HDU-5938 Four Operations(字符串处理)
- HDU 5938 Four Operations 想法题
- HDU 5938 Four Operations (水题乱搞)
- hdu 5938 Four Operations(模拟)
- hdu 5938 Four Operations(乘法四则运算)
- HDU 5938 Four Operations(枚举)
- HDU-5938:Four Operations(DP)
- 2016ccpc杭州赛 hdu 5938 F.Four Operations
- HDU-5938-Four Operations(杭州CCPC F题)-水题
- 查看本机ip等配置
- 图像边缘检测——一阶微分算子 Roberts、Sobel、Prewitt、Kirsch、Robinson(Matlab实现)
- Java基础------重载
- sed实践
- 由Google Protocol Buffer的小例子引起的g++编译问题
- Four Operations HDU
- C#实现图片切割的方法
- HTTP详解(2)-请求、响应、缓存
- docker镜像的问题
- android 开发真机测试,无法安装调试解决
- Remote System Explorer Operation总是运行后台服务,卡死eclipse解决办法
- Vue 2.0 学习笔记
- SQL server修改主键为自动增长
- 动态调试QQ代码,定位系统改动引起的异常