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. HTML Entity Sets - All

    http://www.htmlentities.com/html/entities/ The view below displays the characters used in the offici ...

  2. 关于html中的设置body宽高的理解

    有时候看到别人的代码中经常出现在body中设置的宽高,不是很理解,于是自己测试了下,瞬间懂了,废话不多说,直接上代码: 首先创建好一个基本的html文件,设body的背景色为red: 相信大家都知道效 ...

  3. 智能车学习(二十一)——浅谈CCD交叉以及横线摆放

    一.CCD为何要交叉摆放?       首先使用横线摆放,CCD前瞻如果远一点,弯道丢线,再远一点直接窜道.所以需要很多很多代码的工作量,而且过弯的过程相当于没有任何的调节过程,就是一个偏差保持,或者 ...

  4. 及其简短的Splay代码

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

  5. 提取Windows用户密钥文件cachedump

    提取Windows用户密钥文件cachedump   Windows系统将用户信息和密钥存储在系统存档文件(System hive)和安全存档(Security hive)中.只要提取这些内容,就可以 ...

  6. node express新项目默认主文件app.js

    var express = require('express'); var path = require('path'); var favicon = require('serve-favicon') ...

  7. TeeChart Pro 5.0

    这是Delphi7自带例子 C:\Program Files\Borland\Delphi7\Demos\TeeChart 以下为翻译的文字,有部分不准确. TeeChart Pro 5.0是一个库 ...

  8. 【转】Myeclipse建立Maven项目

    原文地址: http://b-l-east.iteye.com/blog/1246482 1. 使用Maven创建webapp工程----原因是使用Maven时一般需要遵循一定的目录结构,虽然也可以使 ...

  9. Ubuntu Mono 运行 Helloworld

    Ubuntu Mono 运行 Helloworld ref: http://www.mono-project.com/docs/getting-started/install/linux/#usage ...

  10. ccc 正态分布

    cc.Class({ extends: cc.Component, properties: { prefab: { default:null, type:cc.Prefab }, root: { de ...