HDU2577:How to Type(DP)
Pirates
HDUacm
HDUACM
8
8
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
题意:要求一个字符串输入,按键盘的最少次数。有Caps Lock和Shift两种转换大小写输入的方式
思路:用dpa与dpb数组分别记录Caps Lock的开关状态
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; char str[111];
int dpa[111],dpb[111]; int main()
{
int t,i,len,flag;
scanf("%d",&t);
while(t--)
{
scanf("%s",str+1);
dpa[0] = 0;
dpb[0] = 1;
for(i = 1; str[i]; i++)
{
if(str[i]>='a' && str[i]<='z')
{
dpa[i] = min(dpa[i-1]+1,dpb[i-1]+2);//若灯亮,则直接按字母;若灯灭,则按字母再开灯
dpb[i] = min(dpa[i-1]+2,dpb[i-1]+2);//若灯亮,则要先按字母再关灯;若灯灭,则按shift+字母
}
else if(str[i]>='A' && str[i]<='Z')
{
dpa[i] = min(dpa[i-1]+2,dpb[i-1]+2);
dpb[i] = min(dpa[i-1]+2,dpb[i-1]+1);
}
}
printf("%d\n",min(dpb[i-1]+1,dpa[i-1]));//最后要关灯,dpb要+1
} return 0;
}
HDU2577:How to Type(DP)的更多相关文章
- HDU 2577 How to Type (DP,经典)
题意: 打字游戏,求所按的最少次数.给出一个串,其中有大小写,大写需要按下cap键切换到大写,或者在小写状态下按shift+键,这样算两次,打小写时则相反.注意:在打完所有字后,如果cap键是开着的, ...
- POJ1463:Strategic game(树形DP)
Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot f ...
- 计蒜客模拟赛D1T3 蒜头君的坐骑:用dfs转移dp
题目链接:https://nanti.jisuanke.com/t/16447 题意: 蒜头君有一只坐骑,人马. 一天,蒜头君骑着他的坐骑走上了一片n*m的大荒野,一开始时,蒜头君在(1,1)点,他要 ...
- 【转】JAVA错误:The public type *** must be defined in its own file***
出现The public type xxx must be defined in its own file这个问题,是由于定义的JAVA类同文件名不一致.public类必须定义在它自己的文件中. 解决 ...
- QTCreator 调试:unknown debugger type "No engine"
[1]QTCreator调试,应用程序输出:unknown debugger type "No engine" 如图:下断点->调试程序->应用程序输出 说明:调试器无 ...
- delphi 10.1 berlin datasnap提交clientdataset.delta报:invalid variant type conversion(类型转换错误)问题的解决
delphi 10.1 berlin datasnap提交clientdataset.delta报:invalid variant type conversion(类型转换错误)问题的解决,需要打这个 ...
- HTML5学习笔记简明版(5):input的type超级类型
HTML5为input的type类型添加了多种枚举值,用来表达不同的意思.同事具有验证功能,假设格式不正确,浏览器将原始提供错误提示,堪称超级牛X啊,详细例如以下: Keyword Data type ...
- Codeforces 730J:Bottles(背包dp)
http://codeforces.com/problemset/problem/730/J 题意:有n个瓶子,每个瓶子有一个当前里面的水量,还有一个瓶子容量,问要把所有的当前水量放到尽量少的瓶子里至 ...
- Numpy版本问题,import tensorflow as tf 报警:“ FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'”
tensorflow成功安装后 import tensorflow as tf 报警:“ FutureWarning: Passing (type, 1) or '1type' as a synony ...
随机推荐
- SQL2008缩小日志脚本
以下为SQL2008 缩小日志文件的脚本,在SQL Server Management Studio中打开数据库,将脚本里的数据库名称替换成需要缩小日志的库名称,然后 运行以下脚本. USE WSS_ ...
- tomcat中开启的对SSL(https)的支持
打开conf/server.xml会发现有下面一段配置被注释着: <!-- <Connector port="8443" protocol="HTTP/1.1 ...
- Ubuntu切换至root用户
第一种方式: 使用命令 sudo passwd root 设置root用户的密码 然后su root即可切换至root用户 第二种方式: sudo bash
- 关于matlab鼠标响应
今天看了一下Matlab中响应鼠标的事件,整理如下, (1)函数WindowButtonMotionFcn,当鼠标在窗口上运动的时候就会相应此函数,于是在此函数中可以设置运动时想要的代码,如:改变鼠标 ...
- C# 创建文件时,文件夹不存在,如何自动创建文件夹
c# 创建文件时怎么创建文件夹?strhtml=......StreamWriter sw=new StreamWriter("D:/test/1.aspx",false);sw. ...
- Sql Server之数据库规范——1、自动化规范命名
一.废话: 随着数据库的规模越来越大,数据库的表也有成百上千,如果需要对数据库表名及字段名做操作,单个还好,直接一条语句搞定了,但如果要对整个库的所有表和字段名做操作,那就显得有点麻烦了.因此,我们需 ...
- sizeof()的用法
机器平台:X86_64 处理器 操作系统:Red Hat 4.1.2-14 编译器: gcc version 4.1.2 20070626 Size of char is: ...
- leetcode Longest Substring Without Repeating Characters python
class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtyp ...
- SQL2-子查询、join查询
SQL常用高级查询包括:Join查询.子查询. 子查询: USE flowershopdb --子查询:在一个select语句使用另一个select 语句作为条件或数据来源. --查询块:一个sele ...
- Gulp 从0开始
http://www.w3ctech.com/topic/134 (该文章有很多错误) http://markpop.github.io/2014/09/17/Gulp%E5%85%A5%E9%97 ...