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左右的点也求最 ...
随机推荐
- swift-06-字符串,字符以及元组类型
1.字符串和字符类型 //在swift中,字符串使用一对双引号括起来 var str = "hello M.SD-DJ" print(str) //字符也要用双引号括起来,用cha ...
- VMware Workstation不能启用虚拟设备floppy0由于灭有相应的有效设备在主机上. 你要尝试在每次打开虚拟机电源时连接此虚拟设备?
编辑虚拟机的硬件,把软盘取消掉,floppy的提示就没有了
- 还在在专业的blog记录生活吧!
本来觉得自己写文章水平很烂,技术贴也不能保证分析清晰透彻,就决定在百度hi上记录生活随笔.的. 但是,在百度,随便写点啥,都要审核.申诉. 还是在博客园安家吧. 从新手做起.
- 2016.08.06计算几何总结测试day1
T1 bzoj1132[POI2008]TRO 还是太弱了....测试时看到这题直接懵逼,极角排序什么的根本想不起来,只会n^3暴力怎么破......不过竟然有84.....QAQ 正解是n^2log ...
- Sql server 浅谈用户定义表类型
1.1 简介 SQL Server 中,用户定义表类型是指用户所定义的表示表结构定义的类型.您可以使用用户定义表类型为存储过程或函数声明表值参数,或者声明您要在批处理中或在存储过程或函数的主体中使用的 ...
- apache常用工作模式的区别
apache常用工作模式有两种 worker模式1.线程模式2.占用资源少3.稳定性略差4.并发大 prefork模式1.进程模式2.占用资源多3.稳定4.并发一般 来自为知笔记(Wiz)
- C# Linq To DataTable 分组统计 DEMO
DataTable dt = SQLLayer.Get工作量统计(beginDate, endDate); var querySum = from t in dt.AsEnum ...
- Java源代码分析与生成
源代码分析:可使用ANTLRANTLR是开源的语法分析器,可以用来构造自己的语言,或者对现有的语言进行语法分析. JavaParser 对Java代码进行分析 CodeModel 用于生成Java代码 ...
- linux重新增加硬盘容量
1.先用df -h查看硬盘使用情况 2.fdisk -l查看分区情况 表示还没有挂载 3.fdisk /dev/vdb进行分区 4.mkfs.ext3 /dev/vdb进行格式化 5.mount /d ...
- IOS多线程之NSThread
参考:http://blog.csdn.net/totogo2010/article/details/8010231 1 简介 NSThread: 优点:NSThread 比其他两个轻量级 缺点:需要 ...