2016CCPC杭州站 F
来源:互联网 发布:微电脑治疗仪淘宝网 编辑:程序博客网 时间:2024/06/10 23:57
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 into 55 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.
Input
First line contains an integer TT, which indicates the number of test cases.
Every test contains one line with a string only contains digits ‘1’- ‘9’.
Limits
1≤T≤1051≤T≤105
5≤length of string≤205≤length of string≤20
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
1
12345
Sample Output
Case #1: 1
题意:给一个20位之内的数字,让你用分隔符分成五段。然后从左向右依次用+-*/进行运算(有优先级)。
我们不难分析出来,根据优先级减号后面的数字越小越好。这就意味着*号左右只能由两个个位数组成。
a+b-c*d/e
c和d为个位数。
a与b中有一个个位数。
那么枚举除号的位置就好了~
#include<iostream>#include<string.h>#include<stdio.h>#include<math.h>using namespace std;#define LL long longint T;char s[25];int main(){ scanf("%d",&T); LL cas = 0; while(T--){ scanf("%s",s); LL len = strlen(s); LL mx = -1e16; LL p[25]={1}; for(int i=1;i<=16;i++) p[i] = p[i-1]*10; for(int i=3;i<len-1;i++){ LL ans ; LL c = s[i-1] -'0'; LL d = s[i] - '0'; LL a1=0,b1=0,e=0,a2 = 0,b2=0; for(int j=len-1;j>i;j--){ e+=(s[j]-'0')*p[len-1-j]; } a1 = s[0] - '0'; b2 = s[i-2] -'0'; for(int j=i-2;j>=1;j--){ b1 += (s[j]-'0')*p[i-2-j]; } for(int j=i-3;j>=0;j--){ a2 += (s[j]-'0')*p[i-3-j]; } ans = max(a1+b1-c*d/e,a2+b2-c*d/e); mx = max(mx,ans); } printf("Case #%lld: %lld\n",++cas,mx); } return 0;}
- 2016CCPC杭州站 F
- 2016 CCPC 杭州站 总结
- 2016CCPC杭州站 A
- 2016CCPC杭州站 C
- 2016ccpc杭州赛 hdu 5938 F.Four Operations
- HDU 5938 && 2016CCPC杭州 F: Four Operations
- 2016CCPC杭州站打铁纪念
- CCPC杭州站总结
- 2016杭州ccpc
- 2017 CCPC- 杭州站总结!
- CCPC 2016 杭州站 小记 [铁++ → 铁×1]
- HDU-5938-Four Operations(杭州CCPC F题)-水题
- 记2017CCPC杭州站打铁经验
- 2017CCPC杭州站打铁总结
- 2017ccpc赛后总结(杭州站)
- 2016 杭州 ccpc 铜牌旅游经历
- HDU 5935 && 2016CCPC杭州 C: Car
- 2016 CCPC 杭州 几道题的题解
- 在ARM开发板的嵌入式linux系统上运行的QT程序,必须得要在linux里用QT编吗
- 【Java作业】2017.10.21 / 10.22
- 中控考勤机网络化方案
- java高并发程序设计学习笔记八BIO、NIO和AIO
- Baseball Game(leetcode)
- 2016CCPC杭州站 F
- MySQL5.7主从复制配置,数据同步
- DISTINCT 用法
- action-sheet和showActionSheet的区别
- leetcode 48. Rotate Image
- JDBC 连接MYSQL数据库
- 习题3(3.1)2
- 周中记录--2017.10.26
- daterangepicker-- 日期区间选择器