How to Type

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

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

 题解:
开一个二维数组,0代表当前输入结束lock是关着的;1代表开着的;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define SD(x,y) scanf("%lf%lf",&x,&y)
#define P_ printf(" ")
const int MAXN=110;
typedef long long LL;
int dp[2][MAXN];
bool is_bigalpha(char c){
if(c>='A'&&c<='Z')return true;
else return false;
}
int main(){
int T;
char s[MAXN];
SI(T);
while(T--){
mem(dp,0);
scanf("%s",s+1);
int len=strlen(s+1);
dp[0][0]=0;
dp[1][0]=1;
for(int i=1;i<=len+1;i++){
if(is_bigalpha(s[i])){
dp[0][i]=min(dp[0][i-1]+2,dp[1][i-1]+2);
dp[1][i]=min(dp[0][i-1]+2,dp[1][i-1]+1);
}
else{
dp[0][i]=min(dp[0][i-1]+1,dp[1][i-1]+2);
dp[1][i]=min(dp[0][i-1]+2,dp[1][i-1]+2);
}
}
printf("%d\n",min(dp[0][len],dp[1][len]+1));
}
return 0;
}

  

How to Type(dp)的更多相关文章

  1. hdu 2577 How to Type(dp)

    Problem Description Pirates have finished developing the typing software. He called Cathy to test hi ...

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

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

  3. HDU2577:How to Type(DP)

    Problem Description Pirates have finished developing the typing software. He called Cathy to test hi ...

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

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

  5. BZOJ 1864 三色二叉树 - 树型dp

    传送门 题目大意: 给一颗二叉树染色红绿蓝,父亲和儿子颜色必须不同,两个儿子颜色必须不同,问最多和最少能染多少个绿色的. 题目分析: 裸的树型dp:\(dp[u][col][type]\)表示u节点染 ...

  6. fix orphaned user

    orphan user是某个数据库的user,只有user name而没有login,即,在存在于sys.database_principals 中, 而不存在于 sys.server_princip ...

  7. Linq 动态查询排序

    Linq的排序一般是这样写的: query.OrderBy(x => x.Tel).Skip().Take(); 实际使用中排序字段可能是通过字符类型的参数来设置的,于是想这样实现: query ...

  8. Func 委托

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. C# ftp 图片上传多快好省

    前言 此篇讲到的是图片上传功能,每个网站必定会有这样类似的功能,上传文件.上传图片等等.那么接下来,看看我们EF+uploadfile+ftp如何玩转上传图片吧 效果预览 具体实现 一个简单数据库 只 ...

随机推荐

  1. css案例学习之class执行的顺序

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. 理解Java多态

    多态又称Polymophism,poly意思为多,polymophism即多种形态的意思.一种类型引用因为指向不同的子类,表现出不同的形态,使用不同的方法. 什么是多态 多态建议我们编码时使用comm ...

  3. Hibernate 1、Hello Hibernate

    所使用到的jar 包: 1.创建实体类 public class User { private Integer id; private String name; private String addr ...

  4. 用C#实现生成PDF文档

    using System; using System.IO; using System.Text; using System.Collections; namespace PDFGenerator { ...

  5. ContextMenuStrip 添加在窗体。点击右键不能显示问题解答

    ContextMenuStrip控件,系统默认为点击菜单,使用时.需要与你的窗体绑定.如图所示,,form窗体上包括一个contextMenustrip信息.默认状态是无.所以在使用contextMe ...

  6. 自定义Toast样式-两行文本居中显示

    toast可以设置自定义的view和显示位置.下面是一个简单的例子,复杂些的就是改变其布局文件就可以了. /** * @author BMR * @ClassName: ToastWithTwoTex ...

  7. 关于if (!cin)以及while (cin >> word)

    首先注意: 1.每一个输入(输出)对象就代表一个输入(输出)流: 2.输入(输出)对象中的流状态成员标记了输入(输出)流当前的状况,当eofbit.badbit.failbit三个标记位均为0时表示流 ...

  8. Nodejs随笔(一):Hello World!

    声明:本人用的是Ubuntu 14.04 LTS 系统. 一.Nodejs安装: <1>直接apt-get安装,最简单:sudo apt-get install nodejs <2& ...

  9. Spring 4.0 中的 WebSocket 架构

    两年前,客户端与服务器端的全双工双向通信作为一个很重要的功能被纳入到WebSocket RFC 6455协议中.在HTML5中,WebSocket已经成为一个流行词,大家对这个功能赋予很多构想,很多时 ...

  10. c++多线程同步使用的对象

    线程的同步 Critical section(临界区)用来实现“排他性占有”.适用范围是单一进程的各线程之间.它是: ·         一个局部性对象,不是一个核心对象. ·         快速而 ...