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. 出来ios顶部导航掉下来问题

    <script type="text/javascript"> setposition(); function setposition(){ var ua = navi ...

  2. 如何离线下载Chrome的安装包

    打开Chrome官网(自行搜索)点击下载后下载的是联网安装包,这对部分上网不方便的用户造成了一定的麻烦. http://www.google.cn/chrome/browser/desktop/ind ...

  3. Loadrunner中百分比模式和Vuser模式

    从百分比模式切换到Vuser模式后,多个脚本时候,每个脚本的比例仍然维持不变: 切换到Vuser模式后: 如果在场景执行过程中需要动态添加Vuser,只能在Vuser模式下执行场景 如果需要执行“组” ...

  4. Class.forName()的作用与使用总结

    1.Class类简介: Java程序在运行时,Java运行时系统一直对所有的对象进行所谓的运行时类型标识.这项信息纪录了每个对象所属的类.虚拟机通常使用运行时类型信息选准正确方法去执行,用来保存这些类 ...

  5. json入门(二)

    背景 之前最早的时候,也见过类似于这样的字符串: {"list":[           {"ArticleId":7392749,"BlogId&q ...

  6. Uva 839 Not so Mobile

    0.最后输出的yes no的大小写 1.注意 递归边界   一直到没有左右子树 即b1=b2=false的时候 才返回 是否 天平平衡. 2.注意重量是利用引用来传递的 #include <io ...

  7. Android手机自动化测试真机运行

    一,    打开手机的USB调试模式 不同的手机有不同的方法打开usb调试模式,可是去网上查一下你手机的调试模式打开办法(http://wenku.baidu.com/view/3077f06c25c ...

  8. Thymeleaf 常用属性

    Thymeleaf 常用属性 如需了解thymeleafThymeleaf 基本表达式,请参考<Thymeleaf 基本表达式>一文 th:action 定义后台控制器路径,类似<f ...

  9. HIVE 创建外部分区表--利用HUE不能创建外部表

    Create EXTERNAL table obd_data_2( imei string, ts timestamp, fuel_instant float, gps_speed float, gp ...

  10. 解决Ue4C++使用UMG之类的模块时出现的拼写错误

    在cs文件中加入UMG模块后,在项目文件上右键生成项目文件即可解决