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 ...
随机推荐
- Nutch安装的几个网址
RunNutchInEclipse - Nutch Wiki http://wiki.apache.org/nutch/RunNutchInEclipse Index of /apache/nut ...
- Sql Sever 字符串截取汉字
最近需要在SQL的字符串中截取汉字,利用unicode函数判断字符的unicode编码,根据编码范围过滤掉非汉字字符. 写成了一个function /*@str 需要获取汉字的字符串*/ create ...
- sql查询当天数据
向数据库中添加日期 MS SQL SERVER: NSERT into student(studentid,time1)values('15',getdate()); MY SQLinsert int ...
- NSURLSessionConfiguration的简单实用
NSURLSessionConfiguration 基于前面学习了NSURLSession的知识,这边文章就讲下NSURLSessionConfiguration相关应用,(这名字可真长). 简而言之 ...
- poj 1091 跳骚
/** 题意: 求对于小于m的n个数, 求x1*a1 + x2*a2+x3*a3........+xn*an = 1 即求 a1,a2,a3,....an 的最大公约数为1 , a1,a2....an ...
- 电脑Win7如何取得文件管理所有权(提供各种GHOST版本的Windows)
电脑Windows7系统如何取得文件管理所有权?从 VISTA开始,微软对操作系统的安全性有了明显的提高,这样使得以前我们在XP下都可以打开或删除的文件(夹),无法在WIN7下进行操作.就算是在 Ad ...
- Qt信息隐藏(Q_D/Q_Q)介绍——从二进制兼容讲起
http://www.cnblogs.com/SkylineSoft/articles/2046404.html
- android网络通讯数据封装之 json
Demo程序包括客户端和服务端 客户端按json数据格式封装数据传至服务端. 服务端为简单的servlet程序,负责接收客户端传到json数据,然后按原数据返回客户端. 实例代码如下: public ...
- 调用Android自带日历功能(日历列表单、添加一个日历事件)
调用Android自带日历功能 觉得这篇文章不错,转载过来. 转载:http://blog.csdn.net/djy1992/article/details/9948393 Android手机配备有 ...
- one Infos
Backend Server is still running (PID:). Please try 'euc-server stop' first. (原因很简单,进程控制脚本无restart函数功 ...