hdu5938Four Operations
来源:互联网 发布:广州淘宝模特 编辑:程序博客网 时间:2024/06/05 00:20
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5938
题意:给一个只含'1'~'9'的字符串,要求按顺序插入'+','-','*','/',求运算结果中的最大值。
分析:要求运行结果最大,设为a+b-c*d/e很明显我们能观察到要让前面a+b尽量大即a<10或b<10以及cde的时候e要尽量大c*d尽量小即c<10和d<10,那么我们只需要枚举-号的位置,我们就能确定运算答案。
代码:
#include<map>#include<set>#include<stack>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<vector>#include<string>#include<stdio.h>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;typedef double db;typedef long long ll;typedef unsigned int uint;typedef unsigned long long ull;const db eps=1e-8;const int N=1e2+10;const int M=2e5+10;const ll MOD=1000000007;const int mod=1000000007;const int MAX=1000000010;const double pi=acos(-1.0);ll a,b,c,ans;char s[25];int main(){ int i,j,T,ca,len; scanf("%d", &T); for (ca=1;ca<=T;ca++) { scanf("%s", s); len=strlen(s);ans=-MOD; for (i=1;i<len-3;i++) { a=b=c=0ll; for (j=0;j<i;j++) a=a*10ll+s[j]-'0'; a+=s[i]-'0'; for (j=1;j<=i;j++) c=c*10ll+s[j]-'0'; c+=s[0]-'0'; a=max(a,c);c=0ll; b=(s[i+1]-'0')*(s[i+2]-'0'); for (j=i+3;j<len;j++) c=c*10ll+s[j]-'0'; b/=c; ans=max(ans,a-b); } printf("Case #%d: %lld\n", ca, ans); } return 0;}
0 0
- hdu5938Four Operations
- Operations
- NDISUIO Operations
- js operations
- string Operations
- Boolean Operations
- wifi operations
- Windbg operations
- Bit Operations
- Boolean Operations
- Talend Operations
- ioctl Operations
- Operations-tools
- SQLite operations
- Mininet Operations
- Lecture2 Operations
- Heap Operations
- Heap Operations
- iOS跳转界面时隐藏tabBar的方法
- Singleton 单例模式(懒汉方式和饿汉方式)
- Unity发布到iOS平台后的相关问题
- express和body-parser的登录项目
- codevs 1058 合唱队形(DP)
- hdu5938Four Operations
- Android 框架的组成
- UIScrollView配合定时器自动循环滚动
- Triangle
- php中百度编辑器的使用
- 【MySQL】MySQL的数据类型
- 13. Roman to Integer
- IOS开发之UIScrollViewDelegate详解
- 1029. Median (25)