How to Type

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6072    Accepted Submission(s): 2729

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

 
Author
Dellenge
 
Source
 
Recommend
lcy
题意:
问你打一串字母需要最少的按几次键盘。caps lock亮着时按shift可以打印小写字母!
思路:
每一次打字母时的总按键数都可以由前一次的推断出来,
当为大写字母时:  st[i+1][0]=min(st[i][0]+2,st[i][1]+2);
                       st[i+1][1]=min(st[i][0]+2,st[i][1]+1);
小写字母时:      st[i+1][0]=min(st[i][0]+1,st[i][1]+2);
                       st[i+1][1]=min(st[i][0]+2,st[i][1]+2);
st[0][0],st[0][1]分别初始化为0和1.
最后如果capslock亮,还要再加1.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-);
const int MAXN = ;
int t, f[][];
char s[];
int main()
{
scanf("%d", &t);
while (t--) {
scanf("%s", s + );
int len = strlen(s + );
f[][] = ; f[][] = ;
for (int i = ; i <= len; ++i) {
if (s[i] >= 'a' && s[i] <= 'z') {
f[i][] = min(f[i - ][] + , f[i - ][] + );
f[i][] = min(f[i - ][] + , f[i - ][] + );
}
else {
f[i][] = min(f[i - ][] + , f[i - ][] + );
f[i][] = min(f[i - ][] + , f[i - ][] + );
}
}
printf("%d\n", min(f[len][], f[len][] + ));
}
return ;
}

HDU 2577的更多相关文章

  1. DP问题(1) : hdu 2577

    题目转自hdu 2577,题目传送门 题目大意: 现给你n个区分大小写的字符串,大小写可用Caps Lock和shift切换(学过计算机的都知道) 但是有一点需要注意(shift是切换,若现在是大写锁 ...

  2. HDU 2577 How to Type(dp题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...

  3. HDU 2577 How to Type (线性dp)

    How to Type Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  4. HDU 2577 How to Type DP也可以模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=2577 大意: 大家都打过字吧,现在有个有趣的问题:给你一串字符串,有大写有小写,要求你按键次数最少来输出它,输出 ...

  5. HDU 2577 分情况多维DP

    How to Type Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. HDU 2577(DP)

    题意:要求一个字符串输入,按键盘的最少次数.有Caps Lock和Shift两种转换大小写输入的方式 思路:用dpa与dpb数组分别记录Caps Lock的开关状态,dpa表示不开,dpb表示开 代码 ...

  7. 【HDU 2577】How to Type

    题意 (我做了这题才知道caps lock 锁定大小写后,按一下shift键可以输入相反的大小写.) 这题就是给你只有大小写字母的字符串,求最少多少次按键盘.最后caps lock 必须是关闭的. 分 ...

  8. HDU 2577 How to Type【DP】

    题意:给出一个字符串,有大写有小写,问最少的按键次数.然后打字的这个人有一个习惯,打完所有的字之后,指示灯要关闭. dp[i][j]表示打到第i个字母,j有0,1两个值表示指示灯开或者关的状态 然后就 ...

  9. HDU 2577 How to Type (DP,经典)

    题意: 打字游戏,求所按的最少次数.给出一个串,其中有大小写,大写需要按下cap键切换到大写,或者在小写状态下按shift+键,这样算两次,打小写时则相反.注意:在打完所有字后,如果cap键是开着的, ...

随机推荐

  1. Linux学习笔记(12)用户和用户组管理

    越是对服务器安全性要求高的服务器,越需要建立合理的用户权限等级制度和服务器操作规范.在Linux中主要是通过用户配置文件来查看和修改用户信息. 1 用户信息文件 (1)用户信息文件/etc/passw ...

  2. cdoj1324暴力分块

    #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> ...

  3. 及其简短的Splay代码

    #include <stdio.h> #include <queue> #include <algorithm> #include <stdlib.h> ...

  4. Linux常用工具之XFTP、Xshell配置

    Xftp是一个基于 MS windows 平台的功能强大的SFTP.FTP文件传输软件.使用了 Xftp 以后,MS windows 用户能安全地在UNIX/Linux 和 Windows PC 之间 ...

  5. python 文件操作总结

    Python 文件I/O 本章只讲述所有基本的的I/O函数,更多函数请参考Python标准文档. 打印到屏幕 最简单的输出方法是用print语句,你可以给它传递零个或多个用逗号隔开的表达式.此函数把你 ...

  6. Android Manifest 权限描述大全

    权限 名称 描述 android.permission.ACCESS_CHECKIN_PROPERTIES 访问登记属性 读取或写入登记check-in数据库属性表的权限 android.permis ...

  7. Uva 524 Prime Ring

    如果用全排列生成之后,在判断是否是素数环是会超时的,应该用回溯. 回溯的时候  首先要注意 递归边界 ,结束的时候别忘记判断最后一个和第一个元素能否成立  还有要记得vis的使用和递归之后的清理. # ...

  8. Uva 725 Division

    0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...

  9. DSP using MATLAB 示例Example2.3

    n = [-10:1:10]; alpha = -0.1+0.3j; % x = exp(alpha*n); % subplot(2,1,1); set(gcf,'Color',[1,1,1]) % ...

  10. 5、利用控件TVCLZip和TIdFTP压缩文件并上传到FTP的线程单元pas 改进版

    用到临界区 保护写日志的函数: 递归函数 删除目录下的所有文件: 循环创建或判断FTP的目录: 可改进的地方:循环压缩深层次目录的所以文件: 实现断点续传,或断点下载: {************** ...