HDOJ --- 2577
How to Type Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3261 Accepted Submission(s): 1509 Problem Description
Pirates have finished developing the typing software. He called Cathy to test his typing software. She is good at thinking. After testing for several days, she finds that if she types a string by some ways, she will type the key at least. But she has a bad habit that if the caps lock is on, she must turn off it, after she finishes typing. Now she wants to know the smallest times of typing the key to finish typing a string. Input
The first line is an integer t (t<=100), which is the number of test case in the input file. For each test case, there is only one string which consists of lowercase letter and upper case letter. The length of the string is at most 100. Output
For each test case, you must output the smallest times of typing the key to finish typing this string. Sample Input
3
Pirates
HDUacm
HDUACM Sample Output
8
8
8 Hint The string “Pirates”, can type this way, Shift, p, i, r, a, t, e, s, the answer is 8.
The string “HDUacm”, can type this way, Caps lock, h, d, u, Caps lock, a, c, m, the answer is 8
The string "HDUACM", can type this way Caps lock h, d, u, a, c, m, Caps lock, the answer is 8
思路:openclock[i]记录到i位置打开大写键时的最小按键次数,closeclock[i]记录到i位置时不打开大写键时最小按键次数,详见代码。
#include<ctype.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#define MAX 111
using namespace std;
int closeclock[MAX], openclock[MAX];
char str[MAX];
int main(){
int c, len;
/* freopen("in.c", "r", stdin); */
scanf("%d", &c);
while(c--){
memset(str, , sizeof(str));
scanf("%s", str);
len = strlen(str);
openclock[] = ;
for(int i = len;i > ;i --) str[i] = str[i-];
for(int i = ;i <= len;i ++){
if(islower(str[i])){
openclock[i] = min(openclock[i-]+, closeclock[i-]+);
closeclock[i] = min(openclock[i-]+, closeclock[i-]+);
}else{
openclock[i] = min(openclock[i-]+, closeclock[i-]+);
closeclock[i] = min(openclock[i-]+, closeclock[i-]+);
}
}
openclock[len]++;
printf("%d\n", min(openclock[len], closeclock[len]));
}
return ;
}
HDOJ --- 2577的更多相关文章
- 【HDOJ】2577 How to Type
DP. /* 2577 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MAX ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- hdoj 1385Minimum Transport Cost
卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...
- HDOJ(2056)&HDOJ(1086)
Rectangles HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...
- 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ
前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...
- 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design
题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...
随机推荐
- [开发环境] Ubuntu12.04 Telnet服务设置
Ubuntu12.04默认未启用Telnet服务,配置Telnet服务步骤如下: 1. 安装和配置 安装openbsd-inetd: #sudo apt-get install openbsd-ine ...
- (jQuery 插件)封装容器的表单为json对象
下面代码可以把一个页面容器中的表单元素封装成一个json对象. (function($){ $.fn.serializeObject=function(){ var inputs=$(this).fi ...
- HTML5 声明兼容IE的写法
<!DOCTYPE html> <!–[if IE]> <meta http-equiv=”X-UA-Compatible” content=”IE=8″ /> & ...
- ubuntu基本操作(2)
查看当前使用那种 shell echo $SHELL 更换 shell 类型:首先检查是否安装了相应的类型 shell开启终端,直接输入相应的 shell 名称如果没有安装,则先安装,否则直接启动此时 ...
- 使用Fiddler提高前端工作效率 (实例篇)
上篇中,我们对Fiddler Web Debugger有了简单的接触,也许你已经开始在用Fiddler进行HTTP相关的调试,在这一篇,我们将通过一个实例了解Fiddler的神奇魔法. 在我们前端开发 ...
- PHP输出图片文件,实现浏览器缓存机制
$ETag = '"'.md5($file).'"'; if(env('HTTP_IF_NONE_MATCH') === $ETag){ header ( 'ETag: '.$ET ...
- KeepAlive详解
KeepAlive既熟悉又陌生,踩过坑的同学都知道痛.一线运维工程师踩坑之后对于KeepAlive的总结,你不应该错过! 最近工作中遇到一个问题,想把它记录下来,场景是这样的: 从上图可以看出,用户通 ...
- osg学习笔记3 简单几何模型
osg::Geode (geometry node) osg::Geode类表示场景中的渲染几何叶节点,它包含了渲染用的几何信息,没有子节点. 要绘制的几何数据保存在osg::Geode管理的一组os ...
- PHP javascript 值互相引用(不用刷新页面)
PHP javascript 值互相引用的问题 昨天通过EMAIL给一些公司投了简历,希望他们能给我一份工作,今天其中一家公司的人给我打电话,大意是要我做一点东西(与AJAX有关) 给他们看,我听 ...
- POJ 2886 Who Gets the Most Candies? 线段树
题目: http://poj.org/problem?id=2886 左右转的果断晕,题目不难,关键是准确的转啊转.因为题目要求输出约数个数最多的数,所以预处理[1,500000]的约数的个数就行了. ...