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. 1016. 部分A+B

    /* * Main.c * 1016. 部分A+B * Created on: 2014年8月30日 * Author: Boomkeeper *******测试通过********* */ #inc ...

  2. 960 grid 分析

    960 网格系统的构造如下:页面总宽度 960px12 栏布局, 每栏 60px每栏两边保留 10px 的外边距, 相当于 20px 的槽内容区域总宽度是 940px 960 布局无疑是非常好的网格系 ...

  3. W5300E01-ARM 交叉编译器(Cross Compiler)用户手册

    W5300E01-ARM是基于W5300的ARM功能测试评估板: 1      简介 当用户的开发环境与目标系统不同时就会用到交叉编译器. 例如,当开发基于ARM的嵌入式系统时,用户就需要在电脑上写出 ...

  4. MD5 32位、16位加密

    /// <summary> /// MD5 16位加密 /// </summary> /// <param name="ConvertString"& ...

  5. ios的标志常量

    1 dec 2 fixed 3 hex 4 internal 5 left 6 oct 7 right 8 scientific 9 showbase 10 showpoint 11 showpos ...

  6. 获取枚举Name,Value,Description两种方法

    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...

  7. Android创建启动画面[转]

    每个Android应用启动之后都会出现一个Splash启动界面,显示产品的LOGO.公司的LOGO或者开发者信息.如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥 ...

  8. HDOJ 2689

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  9. ftp 解决不能上传问题

    有人建议整个关掉SELinux并且重启,于是我去/etc/selinux/config里面把SELinux给disable了.重启之后,发现可以在/home/sam/test这个文件夹上传了!

  10. OC 实现多选参数

    在iOS的开发过程中有许多方法都是有可选参数的,例如: + (instancetype)arrayWithObjects:(ObjectType)firstObj, ... NS_REQUIRES_N ...