#HDU 2577 How to Type ?
来源:互联网 发布:男士风衣品牌 知乎 编辑:程序博客网 时间:2024/06/04 18:50
How to Type?
题意: 给一串有26个字母(大小写都可能有)组成的字符串,现在按照题目给的要求敲出来,问最少的敲击次数。这个人打字喜欢让caps键灭掉。
分析:因吹丝听!刚开始还没有理解题意,原来 caps 不亮的情况下也可以用 shift + 字母;亮的情况下可以用 shift+字母打出小写字母。
代码如下:
#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define TEST cout<<"stop here"<<endl using namespace std;typedef long long ll;const ll mod = 1e9 + 7;int dp_a[105],dp_A[105];//表示灯灭或者亮int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); int t; cin>> t; while(t--){ memset(dp_a,INF,sizeof(dp_a)); memset(dp_A,INF,sizeof(dp_A)); string s; cin>> s; int len = (int)s.size(); dp_a[0] = 0,dp_A[0] = 1;//灯亮初始值要是1 for(int i=1;i<=len;i++){ if(s[i-1]>='a' && s[i-1]<='z'){//小写字母 dp_a[i] = min(dp_a[i-1]+1,dp_A[i-1]+2);//字母/caps+字母 结果:灭 dp_A[i] = min(dp_a[i-1]+2,dp_A[i-1]+2);//字母+caps/shift+字母 结果:亮 } if(s[i-1]>='A' && s[i-1]<='Z'){ dp_a[i] = min(dp_a[i-1]+2,dp_A[i-1]+2);//shift+字母/字母+caps 结果:灭 dp_A[i] = min(dp_a[i-1]+2,dp_A[i-1]+1);//caps+字母/字母 结果:亮 } } cout<< min(dp_a[len],dp_A[len]+1) <<endl;//dp_A[]表示灯亮着的情况,结束要关灯 } return 0;}
阅读全文
0 0
- hdu 2577 How to Type
- HDU-2577-How to Type
- HDU 2577 how to type
- HDU 2577 How to Type
- hdu 2577 How to Type
- Hdu 2577 How to Type
- HDU 2577 how to type
- hdu 2577 How to Type
- hdu 2577 How to Type
- HDU 2577 How to Type
- hdu 2577 How to Type
- HDU - 2577 How to Type
- hdu 2577 How to Type
- HDU - 2577 How to Type
- HDU 2577 How to Type
- HDU 2577 How to Type
- HDU 2577 How to Type
- HDU 2577 How to Type
- 一个女程的自我告白
- spring接收json格式的多个对象参数
- Educational Codeforces Round 26
- Window本地安装与启用MongoDB
- java并发计数器问题
- #HDU 2577 How to Type ?
- 动态规划中级教程 377. Combination Sum IV
- WUST 1255 巧克力(线段树的单点区间更新查询)
- 播放wav, PlaySound不太靠谱,有时没有声音,原因未知,改用MCI函数,尚未测试
- 微信-----信息加密与解密流程图的过程
- JAVA中ListIterator和Iterator详解与辨析
- SOAP WebService 短信接口对接
- 【文献阅读】Densely Connected Convolutional Networks-best paper-CVPR-2017
- POJ-2689 Prime Distance(区间素数筛--经典题)