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. ARM 开发工具 Keil和DS-5的比较。

    http://www.eeboard.com/bbs/thread-25219-1-1.html 如今ARM体系架构的处理器在嵌入式市场上呼风唤雨,从低端的MCU应用到高端的多媒体消费电子,移动设备领 ...

  2. PostgreSQL Replication之第一章 理解复制概念(1)

    PostgreSQL Replication系列翻译自PostgreSQL Replication一书 在本章中,将会介绍不同的复制概念,您会了解哪些类型的复制对哪一种实用场景是最合适的. 在本章的最 ...

  3. oracle归档模式和非归档模式的切换

    Oracle从未归档日志改成归档日志: SQL> shutdown immediate; 数据库已经关闭. 已经卸载数据库. Oracle 例程已经关闭. SQL> startup mou ...

  4. Unit01: JAVA开发环境案例

    Top JAVA Fundamental DAY01 JDK及Eclipse目录结构操作 JDK的安装及配置 控制台版的JAVA HelloWorld 使用Eclipse开发Java应用程序 1 JD ...

  5. JavaSE基础第一篇

      1.JDK的安装: 包括JRE 和JVM   下载地址: www.oracle.com/www.sun.com 2.环境变量 set path = "bin所在路径" 设置pa ...

  6. Windows服务安装与卸载

    Windows服务安装与卸载,使用到了InstallUtil.exe 安装: c: cd "C:\Windows\Microsoft.NET\Framework\v4.0.30319&quo ...

  7. [Vuejs] 关于vue-router里面的subRoutes

    刚学习vue,可能有使用不对的地方,希望没有对大家造成困扰! 使用vue-router,为了能够更好的管理.vue文件,需要用到子路由. 先看个错误的例子 routers.js '/company': ...

  8. oracle存储过程常用技巧

    我们在进行pl/sql编程时打交道最多的就是存储过程了.存储过程的结构是非常的简单的,我们在这里除了学习存储过程的基本结构外,还会学习编写存储过程时相关的一些实用的知识.如:游标的处理,异常的处理,集 ...

  9. 捷波朗 jabra BT3030 蓝牙耳机

    蓝牙版本V2.0 通话时间 8小时 按键说明:轻敲 快按轻敲两下 在1.5秒内快速按两下按 大约 1秒钟按住 大约 4秒钟 充电提示绿灯闪亮 正在充电持续绿灯 已完全充满电 检查电量按 音量上调(+) ...

  10. Makefile使用库

    这篇文章演示了Makefile使用mysqlpp库和lua库的写法. test.cpp: #include <iostream> #include <stdint.h> #in ...