HDU 5938 Four Operations(四则运算)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

 

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 into 5 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.
小Ruins是个好学的男孩纸,最近他在学四则运算!

现在他打算练练四则运算。此处有个由数字'' - ''组成的字符串,依次添加'+', '-', '*' , '/'这四个运算符把字符串划分为5个部分,再算出结果(/ 使用整数除法)。

帮他找出可以获得的最大值吧!

CN

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
第一行为一个整数T,表示测试用例的数量。

每个测试用例为一个仅由数字 ''-'' 组成的字符串。

数据范围
<= T <= ^
<= 字符串长度 <=

CN

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.
对于每组测试用例,输出"Case #x: y",x表示从1开始的用例编号,y为结果。

CN

Sample Input - 输入样例

1
12345

Sample Output - 输出样例

Case #1: 1

题解

  模拟水题。
  一个只有5个部分,可以写成A+B-C*D/E
  要使结果最大,则A+B最大,C*D/E最小
  A+B最大,加号要么在第一位数后面,要么在最后一位数前面。
  C*D/E最小,C和D都是1位数,E只有可能是1~3位数,到3位数的时候已经为0了。
  所以最多只要就算三次即可,注意初始化。

代码 C++

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define ll __int64
char data[]; int main(){
int t, it, i, j, len;
ll opt, l, r, L, R, L10, R10;
for (it = scanf("%d ", &t); it <= t; ++it){
opt = (ll) << ;
gets(data); len = strlen(data);
L = ; L10 = ;
for (i = ; i < len - ; ++i, L10 *= ) L = L * + data[i] - '';
L10 /= ;
R = ; R10 = ;
j = std::min(, len - );
for (i = ; i <= j; ++i){
R = (data[len - i] - '')*R10 + R;
R10 *= ;
l = std::max(L / L10 + L % L10, L / + L % );
L10 /= ; L /= ;
r = (data[len - i - ] - '')*(data[len - i - ] - '') / R;
opt = std::max(opt, l - r);
}
printf("Case #%d: %I64d\n", it, opt);
}
return ;
}

HDU 5938 Four Operations(四则运算)的更多相关文章

  1. HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))

    Four Operations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. HDU 5938 Four Operations 【字符串处理,枚举,把数字字符串变为数值】

    Problem Description Little Ruins is a studious boy, recently he learned the four operations! Now he ...

  3. HDU 5938 Four Operations(乱搞)题解

    题意:把'+', '-', '*' 和'/'按顺序插入任意两数字间隔,使得操作得到后计算后最大. 思路:没想到是个水题,打的时候想得太复杂了.这道题其实只要考虑*和/.显然我们要把a*b/c弄到最小. ...

  4. HDU 6351 Naive Operations(线段树)

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=6315 Naive Operations Time Limit: 6000/3000 MS (Java/O ...

  5. HDU 6315 Naive Operations(线段树区间整除区间)

    Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b i ...

  6. hdu 6315 Naive Operations (2018 Multi-University Training Contest 2 1007)

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  7. HDU 6315: Naive Operations

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  8. HDU-DuoXiao第二场hdu 6315 Naive Operations 线段树

    hdu 6315 题意:对于一个数列a,初始为0,每个a[ i ]对应一个b[i],只有在这个数字上加了b[i]次后,a[i]才会+1. 有q次操作,一种是个区间加1,一种是查询a的区间和. 思路:线 ...

  9. 杭电多校第二场 hdu 6315 Naive Operations 线段树变形

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

随机推荐

  1. APP开发:对于IOS APP应用的推广渠道有哪些?

    亿合科技了解到,随着移动互联网时代的到来,苹果从2007年进入中国市场,一直备受大众喜爱,手机应用也层出不穷.那么对于那么多的IOS APP应用怎么能获得用户的喜爱呢?于是推广APP应用是需要做的,亿 ...

  2. servlet获取参数时,request.getParameter("id")参数获取失败

    servlet获取参数时,request.getParameter("id")参数获取失败,这里的参数是“index”里面href中的参数 要注意,取不到值,是不是要取的参数有没有 ...

  3. solr 日期查询格式

    //solr 日期格式: SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); //开始 ...

  4. java线程(2016-4-7)

    Thread.yield()的调用是对线程调度器(Java线程机制的一部分,可以将CPU从一个线程转移到另一个线程)的一种建议,它在声明:"我已经执行完生命周期中最重要的部分了,此刻正是切换 ...

  5. Oracle中的日期加减

    加法   select sysdate,add_months(sysdate,12) from dual;        --加1年 select sysdate,add_months(sysdate ...

  6. eclipse安装zylin embedded cdt失败解决办法

    最近再搞嵌入式开发,之前用惯了IDE调试单片机的那种方式,开发2440和am3358驱动时候无法方便的查看寄存器和变量,憋的抓耳挠腮,不爽得很,没有可视化环境进行实时调试观察,太特么蛋疼了.感觉这种情 ...

  7. linux 中压缩记得压缩用c,解压用x

    tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...

  8. Sublime Text 3 高效编码快捷键

    Sublime Text 3 高效编码快捷键   1.快速跳到第20行 Ctrl+p 框中输入 “  :20 ”   2.在文件夹中查看文件 Ctrl+p 框中输入 “ index.html”  更快 ...

  9. 【转】mysql对large page的支持

    昨天同事问我关于大页内存的事,我也只是有个模糊的概念,从别的博客转过来的,先记录下 在 Linux 操作系统上运行内存需求量较大的应用程序时,由于其采用的默认页面大小为 4KB,因而将会产生较多 TL ...

  10. 阿里云mariadb无法启动问题

    需要再安装yum install mariadb-server就可以了, 重启服务器,使用命令 sudo systemctl start mariadb.service