How to Type(dp)
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
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
#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)的更多相关文章
- 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 (DP,经典)
题意: 打字游戏,求所按的最少次数.给出一个串,其中有大小写,大写需要按下cap键切换到大写,或者在小写状态下按shift+键,这样算两次,打小写时则相反.注意:在打完所有字后,如果cap键是开着的, ...
- HDU2577:How to Type(DP)
Problem Description Pirates have finished developing the typing software. He called Cathy to test hi ...
- HDU 2577 How to Type DP也可以模拟
http://acm.hdu.edu.cn/showproblem.php?pid=2577 大意: 大家都打过字吧,现在有个有趣的问题:给你一串字符串,有大写有小写,要求你按键次数最少来输出它,输出 ...
- BZOJ 1864 三色二叉树 - 树型dp
传送门 题目大意: 给一颗二叉树染色红绿蓝,父亲和儿子颜色必须不同,两个儿子颜色必须不同,问最多和最少能染多少个绿色的. 题目分析: 裸的树型dp:\(dp[u][col][type]\)表示u节点染 ...
- fix orphaned user
orphan user是某个数据库的user,只有user name而没有login,即,在存在于sys.database_principals 中, 而不存在于 sys.server_princip ...
- Linq 动态查询排序
Linq的排序一般是这样写的: query.OrderBy(x => x.Tel).Skip().Take(); 实际使用中排序字段可能是通过字符类型的参数来设置的,于是想这样实现: query ...
- Func 委托
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- C# ftp 图片上传多快好省
前言 此篇讲到的是图片上传功能,每个网站必定会有这样类似的功能,上传文件.上传图片等等.那么接下来,看看我们EF+uploadfile+ftp如何玩转上传图片吧 效果预览 具体实现 一个简单数据库 只 ...
随机推荐
- CSS自学笔记(12):CSS3文字特效
在CSS3中新增了多个文本属性,同样有了这些属性我们在进行问题特效处理时,就尽可能少的用到其他软件去制作特效文字了. 在以前使用CSS进行web开发的时候,必须使用计算机上安装好的字体,如果有些用户的 ...
- python 通过ntlm验证下载文件
最近使用python实现一个小工具,需要从网站下载文件,下载时服务端需要进行ntlm验证,否则返回401错误响应.经研究 requests库配合 requests-ntlm 可以解决这个问题. ntl ...
- Javascript 之内置对象
JS提供了11种引用类型:Object.Array.Date.Function.Error.RegExp.Math.Number.String.Boolean.Globle.其中包括了三种基本包装类型 ...
- MYSQL 关闭二进制日志
方法 set sql_log_bin = 0; ---------------------------------------------------------------------------- ...
- 计算机图形学--旋转变换(java)
import java.awt.Color; import java.awt.Frame; import java.awt.Graphics; import java.awt.event.Window ...
- keil MDK编译器警告和错误详解(不定期更新)
工作后从单片机转成ARM,刚开始用ADS1.2编译器,用了一段时间,因为我接手的项目的老程序正是用ADS编译的,部门也大都在用.在学单片机的时候用的是keil c51编译器,ads和这个编译器在易用性 ...
- error LNK2019: 无法解析的外部符号
前些日子电脑系统崩了,重装了了下,原有的项目环境得重新搭建,总是在链接时提示:error LNK2019: 无法解析的外部符号………… 起初以为是库没包含全,可发现不是 有想了下可能是库的包含次序有问 ...
- C#命名空间详解namespace
命名空间是一个域,这在个域中所有的类型名字必须是唯一的,不同的类型分组归入到层次化的命名空间, 命名空间的好处是:1.避免名字冲突,2.便于查找类型名字. 如:System.secruity.Cry ...
- 集合与lamdba
List<, , , , }; List<)); /* foreach (int k in iList2) { Console.WriteLine(k.ToString()); } * * ...
- java日期处理 calendar 和date
抄的人家的,仅作学习使用. java Date获取 年月日时分秒 package com.util; import java.text.DateFormat; import java.ut ...