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. HCE:Host-based Card Emulation基于Android设备的卡片模拟器

    HCE技术支持提供了一个软实现SE的通路,Service实现的方式很多,可以使用文件,使用网络,甚至连接真正的SE.支持HCE的测试手机:目前可以确定使用了NXP PN547作为CLF的NFC手机已经 ...

  2. POJ——字符串插入

    2:字符串插入 查看 提交 统计 提问 总时间限制:  1000ms  内存限制:  65536kB 描述 有两个字符串str和substr,str的字符个数不超过10,substr的字符个数为3.( ...

  3. 二叉查找树的Insert和Delete操作

    struct TreeNode{ SearchTree Left; SearchTree Right; ElementType Ele; }; /*递归一定有出口*/ /*递归代码就是要重复使用*/ ...

  4. HTML5全屏API

    现在大多数浏览器都有全屏功能,允许用户来设置或操作.但HTML5的全屏API与之不同,HTML5的全屏API允许web开发工程师在程序中调用. 这样,web开发工程师就可以再网站中设计一个按钮,当该按 ...

  5. web中使用扫描枪

    扫描枪实际上就是一输入设备,只不过它每次在输入的内容后面添加一个回车.因此在web中可以使用js监听回车事件.处理代码如下: jQuery(function() {        jQuery(doc ...

  6. Examining the Rooms(dp,斯特灵数)

    Examining the Rooms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. MySQL Troubleshoting:Waiting on query cache mutex

    今天被MySQL Query Cache 炕了.线上大量 Waiting on query cache mutex 那么什么是 Query Cache? QC 缓存的是整个SELECT的结果集.而非执 ...

  8. vmlinux,vmlinuz,bzimage,zimage,initrd.img的区别与联系

    1.vmlinux vmlinux是未压缩的内核,vmlinux 是ELF文件,即编译出来的最原始的文件.用于kernel-debug,产生system.map符号表,不能用于直接加载,不可以作为启动 ...

  9. Twitter 新一代流处理利器——Heron 论文笔记之Heron架构

    Twitter 新一代流处理利器--Heron 论文笔记之Heron架构 标签(空格分隔): Streaming-process realtime-process Heron Architecture ...

  10. UVA 103 Stacking Boxes 套箱子 DAG最长路 dp记忆化搜索

    题意:给出几个多维的箱子,如果箱子的每一边都小于另一个箱子的对应边,那就称这个箱子小于另一个箱子,然后要求能够套出的最多的箱子. 要注意的是关系图的构建,对箱子的边排序,如果分别都小于另一个箱子就说明 ...