How to Type

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

Total Submission(s): 6211    Accepted Submission(s): 2804

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
 

本题的意思如hint解释,就是求一段字符串打完需要多少步,记得结束后需保持小写(caps关闭),你有caps和shift两种操作

开dp[105][2]二维数组保存结果,dp[i][0]表示第位输完后保持小写状态,dp[i][1]表示第i位输完后保持大写状态

注意大写转小也是可以用shift的

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
#define inf 0x3f3f3f3f int dp[105][2];
char s[105]; int main()
{
int o;
while(~scanf("%d",&o))
{
while(o--)
{
scanf("%s",&s);
int k=strlen(s);
memset(dp,0,sizeof(dp));
dp[0][1]=1;
for(int i=1; i<=k; i++)
{
if(s[i-1]>='a'&&s[i-1]<='z')
{
dp[i][0]=min(dp[i-1][0]+1,dp[i-1][1]+2);//前一位小写状态+字母,前一位大写状态+shift+字母
dp[i][1]=min(dp[i-1][0]+2,dp[i-1][1]+2);//前一位小写状态+字母+caps,前一位大写状态+shift+字母 }
else
{
dp[i][0]=min(dp[i-1][0]+2,dp[i-1][1]+2);//前一位小写状态+shift+字母,前一位大写状态+字母+caps
dp[i][1]=min(dp[i-1][0]+2,dp[i-1][1]+1);//前一位小写状态+caps+字母,前一位大写状态+字母
} } printf("%d\n",min(dp[k][0],dp[k][1]+1));
} } return 0;
}

 

HDU2577 How to Type 2016-09-11 14:05 29人阅读 评论(0) 收藏的更多相关文章

  1. HDU1078 FatMouse and Cheese(DFS+DP) 2016-07-24 14:05 70人阅读 评论(0) 收藏

    FatMouse and Cheese Problem Description FatMouse has stored some cheese in a city. The city can be c ...

  2. iOS正则表达式 分类: ios技术 2015-07-14 14:00 35人阅读 评论(0) 收藏

    一.什么是正则表达式 正则表达式,又称正规表示法,是对字符串操作的一种逻辑公式.正则表达式可以检测给定的字符串是否符合我们定义的逻辑,也可以从字符串中获取我们想要的特定部分.它可以迅速地用极简单的方式 ...

  3. Hdu2181 哈密顿绕行世界问题 2017-01-18 14:46 45人阅读 评论(0) 收藏

    哈密顿绕行世界问题 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  4. Hadoop入门经典:WordCount 分类: A1_HADOOP 2014-08-20 14:43 2514人阅读 评论(0) 收藏

    以下程序在hadoop1.2.1上测试成功. 本例先将源代码呈现,然后详细说明执行步骤,最后对源代码及执行过程进行分析. 一.源代码 package org.jediael.hadoopdemo.wo ...

  5. Lucene学习总结之四:Lucene索引过程分析 2014-06-25 14:18 884人阅读 评论(0) 收藏

    对于Lucene的索引过程,除了将词(Term)写入倒排表并最终写入Lucene的索引文件外,还包括分词(Analyzer)和合并段(merge segments)的过程,本次不包括这两部分,将在以后 ...

  6. Black Box 分类: POJ 栈和队列 2015-08-05 14:07 2人阅读 评论(0) 收藏

    Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8754 Accepted: 3599 Description ...

  7. iOS中UITextField 使用全面解析 分类: ios技术 2015-04-10 14:37 153人阅读 评论(0) 收藏

    //初始化textfield并设置位置及大小   UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 13 ...

  8. MS SQL数据批量备份还原(适用于MS SQL 2005+) 分类: SQL Server 数据库 2015-03-10 14:32 103人阅读 评论(0) 收藏

    我们知道通过Sql代理,可以实现数据库的定时备份功能:当数据库里的数据库很多时,备份一个数据库需要建立对应的定时作业,相对来说比较麻烦: 还好,微软自带的osql工具,比较实用,通过在命令行里里输入命 ...

  9. A Plug for UNIX 分类: POJ 图论 函数 2015-08-10 14:18 2人阅读 评论(0) 收藏

    A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14786 Accepted: 4994 Desc ...

随机推荐

  1. tensor flow 的两种padding方式

    https://segmentfault.com/a/1190000007846181

  2. 疯狂JAVA——第三章 数据类型和运算符

    3.1注释 1.单行注释 2.多行注释 3.文档注释——文档注释以斜线后紧跟两个星号(/**)开始,以星号后紧跟一个斜线结束(*/),中间部分都是文档注释,会被提取到API文档中. API文档类似于产 ...

  3. win7卸载打印机驱动

    无法删除的话停止Print Spooler服务 删除PRINTERS文件夹下面的文件 C:\Windows\System32\spool\PRINTERS目录下所有的文件,重新启动服务:print s ...

  4. 一些unity问题的收集

    ---恢复内容开始--- 1.Mono打不开且鼠标点击标签页无反应的解决办法 http://answers.unity3d.com/questions/574157/monodevelop-not-o ...

  5. 常用特殊符号的HTML代码(HTML字符实体)

    适当使用实体,对页面开发有相当大的帮助. 自己收集的一些常用的以实体代替与HTML语法相同的字符,避免浏览解析错误. 常用HTML字符实体(建议使用实体): 字符 名称 实体名 实体数 • 圆点   ...

  6. iOS 处理cell选中时背景颜色消息问题

    在cell上添加子控件,在我们点击或者长按的时候,如果子控件有背景颜色,这时候背景颜色就会没有了,这个时候产品经理过来一顿怼,

  7. PAT L2-010 排座位(floyd)

    布置宴席最微妙的事情,就是给前来参宴的各位宾客安排座位.无论如何,总不能把两个死对头排到同一张宴会桌旁!这个艰巨任务现在就交给你,对任何一对客人,请编写程序告诉主人他们是否能被安排同席. 输入格式: ...

  8. linux中使用locate搜索文件方法记录

    在linux中,有时用apt或者yum等软件包管理工具直接安装软件的时候,不知道软件到底安装到哪里去了,配置文件放哪里?这个时候就可以使用搜索命令locate来找到这些文件.海词上locate翻译为找 ...

  9. Docker常见问题

    问题 当我使用docke search mysql时,显示如下错误: [root@iZ25u61v97hZ opt]# docker search redis Segmentation Fault o ...

  10. ADF学习实用网站

    ADF中所有组件工功能例子 http://jdevadf.oracle.com/adf-richclient-demo/faces/components/dialog.jspx;jsessionid= ...