2016ccpc杭州赛 hdu 5938 F.Four Operations
来源:互联网 发布:扣字刷屏软件手机版 编辑:程序博客网 时间:2024/05/19 13:58
Four Operations
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 79 Accepted Submission(s): 38
Problem Description
Little Ruins is a studious boy, recently he learned the four operations!
Now he want to use four operations to generate a number, he takes a string which only contains digits '1' - '9', and split it into5 intervals and add the four operations'+', '-', '*' and '/' in order, then calculate the result(/ used as integer division).
Now please help him to get the largest result.
Now he want to use four operations to generate a number, he takes a string which only contains digits '1' - '9', and split it into
Now please help him to get the largest result.
Input
First line contains an integer T , which indicates the number of test cases.
Every test contains one line with a string only contains digits '1'-'9'.
Limits
1≤T≤105
5≤length of string≤20
Every test contains one line with a string only contains digits '1'-'9'.
Limits
Output
For every test case, you should output 'Case #x: y', where x indicates the case number and counts from 1 and y is the result.
Sample Input
112345
Sample Output
Case #1: 1
Source
2016年中国大学生程序设计竞赛(杭州)
Recommend
liuyiding | We have carefully selected several similar problems for you: 5943 5942 5941 5940 5939
思路:又是一道水题。首先我们看*和/,因为前面有-,所以后面的数要尽可能的小。那么相乘要最小肯定是一位数乘一位数。除的话有两种情况,可能除一位数最小可能除两位数最小,因为一位数乘一位数不可能得到三位数,如果除一个三位数会浪费了一位,然后就是加的部分了,加得到的数最大肯定是一位数加多位数或者多位数加一位数,那么现在答案很明显就只有4种情况,4种求出来取最大就是答案了,下面给代码:
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<cmath>#include<queue>#include<utility>#include<map>#define maxn 25typedef long long LL;using namespace std;const int mod=1e9+7;;char s[maxn];int a[maxn];LL getnum(int l,int r){ LL ans=0; for(int i=l;i<=r;i++){ ans=(ans*10)+a[i]; } return ans;}int main(){ int t; scanf("%d",&t); for(int tcase=1;tcase<=t;tcase++){ scanf("%s",s); int len=strlen(s); for(int i=0;i<len;i++){ a[i]=s[i]-'0'; } LL ans=a[0]+getnum(1,len-4)-a[len-3]*a[len-2]/a[len-1]; ans=max(ans,getnum(0,len-5)+a[len-4]-a[len-3]*a[len-2]/a[len-1]); if(len>5){ int div=getnum(len-2,len-1); ans=max(ans,a[0]+getnum(1,len-5)-a[len-4]*a[len-3]/div); ans=max(ans,getnum(0,len-6)+a[len-5]-a[len-4]*a[len-3]/div); } printf("Case #%d: %lld\n",tcase,ans); }}
0 0
- 2016ccpc杭州赛 hdu 5938 F.Four Operations
- HDU 5938 && 2016CCPC杭州 F: Four Operations
- HDU-5938-Four Operations(杭州CCPC F题)-水题
- CCPC杭州站 HDU5938 Four Operations 贪心 枚举
- HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))
- HDU 5938 Four Operations(2016年中国大学生程序设计竞赛(杭州))
- (2016年中国大学生程序设计竞赛(杭州)) HDU 5938 Four Operations 思维题 + 枚举
- HDU 5938 Four Operations
- hdu 5938 Four Operations
- hdu 5938 Four Operations
- 2016CCPC杭州站 F
- 2016年中国大学生程序设计竞赛(杭州) F Four Operations(暴力枚举)
- HDU 5938 Four Operations(贪心+细节)——2016年中国大学生程序设计竞赛(杭州)
- hdu 5938 Four Operations【贪心】
- hdu 5938 Four Operations 模拟
- HDU 5938 Four Operations 贪心
- HDU 5938 Four Operations 模拟
- HDU 5938 Four Operations(思维)
- C/C++ typedef用法
- pthreads : pthread_cond_signal() from within critical section
- matlab神经网络newff函数的用法
- CodeBlocks 安装与配置
- 判断回文字符串
- 2016ccpc杭州赛 hdu 5938 F.Four Operations
- Android 高仿 QQ5.0 侧滑菜单效果 自定义控件来袭
- 2016年上半年总结
- android 使用百度地图sdk
- 正则表达式
- Vm Funsion使用Fn快捷键
- 旋转数组中最小数
- bestcode Fxx and string
- codevs 1507 酒厂选址 题解报告