Four Operations HDU - 5938
2017-10-25 11:35
99 查看
题目: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占剩余位。
以上条件,我们可以通过枚举减号的位置来确定最终的最大值,实际上还是策略性的暴力解题。
代码
题目大意
将一串数字按顺序划分,满足公式 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; }
相关文章推荐
- HDU 1197 Specialized Four-Digit Numbers
- hdu-oj 1197 Specialized Four-Digit Numbers
- HDU 1197 Specialized Four-Digit Numbers (枚举+进制转化,简单)
- hdu 5938 Four Operations(乘法四则运算)
- hdu 5938 Four Operations(复杂的模拟题)
- HDU 1197 Specialized Four-Digit Numbers
- HDU 5938 Four Operations(贪心+细节)——2016年中国大学生程序设计竞赛(杭州)
- HDU-5938-Four Operations(杭州CCPC F题)-水题
- HDU-5938 Four Operations(字符串处理)
- hdu 5938 Four Operations
- HDU 1197 Specialized Four-Digit Numbers
- hdu 1197 Specialized Four-Digit Numbers
- HDU 1197 Specialized Four-Digit Numbers
- hdu 1197 Specialized Four-Digit Numbers
- HDU 5206 Four Inages Strategy 水题
- hdu 5206 Four Inages Strategy 判断是否是正方形
- 2016ccpc杭州赛 hdu 5938 F.Four Operations
- 杭电 HDU 1197 Specialized Four-Digit Numbers
- hdu 1197 Specialized Four-Digit Numbers
- hdu 5938 贪心 策略(2016年中国大学生程序设计竞赛(杭州))