HDU 2577---How to Type
Description
Input
Output
Sample Input
Sample Output
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 思路: 用dpa[]和dpb[]表示capslk键的开和关状态下的次数; 代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
char s[];
int dpa[],dpb[]; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",s+);
dpa[]=;
dpb[]=;
for(int i=;s[i];i++)
{
if(s[i]>'Z')
{
dpa[i]=min(dpa[i-]+,dpb[i-]+);
dpb[i]=min(dpa[i-]+,dpb[i-]+);
}
else
{
dpa[i]=min(dpa[i-]+,dpb[i-]+);
dpb[i]=min(dpa[i-]+,dpb[i-]+);
}
}
int len=strlen(s+);
printf("%d\n",min(dpa[len],dpb[len]+));
}
}
HDU 2577---How to Type的更多相关文章
- HDU 2577 How to Type (线性dp)
How to Type Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 2577 How to Type(dp题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...
- HDU 2577 How to Type DP也可以模拟
http://acm.hdu.edu.cn/showproblem.php?pid=2577 大意: 大家都打过字吧,现在有个有趣的问题:给你一串字符串,有大写有小写,要求你按键次数最少来输出它,输出 ...
- hdu 2577 How to Type(dp)
Problem Description Pirates have finished developing the typing software. He called Cathy to test hi ...
- HDU 2577 How to Type (字符串处理)
题目链接 Problem Description Pirates have finished developing the typing software. He called Cathy to te ...
- HDU 2577 How to Type (字符串处理)
题目链接 Problem Description Pirates have finished developing the typing software. He called Cathy to te ...
- hdu 2577 How to Type(DP)
How to Type Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 2577 How to Type【DP】
题意:给出一个字符串,有大写有小写,问最少的按键次数.然后打字的这个人有一个习惯,打完所有的字之后,指示灯要关闭. dp[i][j]表示打到第i个字母,j有0,1两个值表示指示灯开或者关的状态 然后就 ...
- HDU 2577 How to Type (DP,经典)
题意: 打字游戏,求所按的最少次数.给出一个串,其中有大小写,大写需要按下cap键切换到大写,或者在小写状态下按shift+键,这样算两次,打小写时则相反.注意:在打完所有字后,如果cap键是开着的, ...
- DP问题(1) : hdu 2577
题目转自hdu 2577,题目传送门 题目大意: 现给你n个区分大小写的字符串,大小写可用Caps Lock和shift切换(学过计算机的都知道) 但是有一点需要注意(shift是切换,若现在是大写锁 ...
随机推荐
- 【书单】book list
正在看: [泡沫经济学].(日)野口悠纪雄 数学模型--姜启源 R in action Programming with R Scrapy Parallel R 准备看: Advanced.A ...
- 萝卜叶万能助手SEO网络营销简介
萝卜叶万能助手专业版是就是将我们10年的SEO经验和方法汇聚于一体的结晶,旨在打造一款使用简单方便,功能强大的SEO软件,以便节省您的时间,提高您收集资料.维护网站.发布帖子.进行网络营销的效率. 借 ...
- preg_match_all正则表达式的基本使用
了解正则表达式之前,须要掌握一些常用的正则表达式的基础知识,这些如果能记得最好记得,记不住须要用的时候能查到就行,就多个特殊字符,所以说正则表达式玩的就是特殊,具体大家可以查看更加细致的说明. pre ...
- Unit Of Work--工作单元(一)
简介 最近忙着新项目的架构,已经有一段时间没有更新博客了,一直考虑着要写些什么,直到有一天跟朋友谈起他们公司开发数据层遇到的一些问题时,我想应该分享一些项目中使用的数据访问模式. 虽然最近一直都在使用 ...
- 表格CSS样式美化
1. 单像素边框CSS表格 这是一个很常用的表格样式. <!-- CSS goes in the document HEAD or added to your external styleshe ...
- STL中vector小结
()使用vector之前必须包含头文件<vector>:#include<vector> ()namespace std{ template <class T, clas ...
- 2014 网选 5007 Post Robot(暴力或者AC_自动机(有点小题大作了))
//暴力,从每一行的开始处开始寻找要查询的字符 #include<iostream> #include<cstdio> #include<cstring> #inc ...
- php分享三十四:待排查问题
1:内存设为1M时,代码不执行,也不报错 ini_set('display_error', 1); error_reporting(E_ALL); ini_set('memory_limit', 10 ...
- [IR] Probabilistic Model
If user has told us some relevant and some irrelevant documents, then we can proceed to build a prob ...
- [git]解决rebase冲突
git pull --rebase时产生冲突 有三个选项: git rebase --skip 效果是:抛弃本地的commit,采用远程的commit(慎用因为你本地的修改就会都没有!) git re ...