Codeforces Round #116 (Div. 2, ACM-ICPC Rules) Letter(DP 枚举)
1 second
256 megabytes
standard input
standard output
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.
To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
Print a single number — the least number of actions needed to make the message fancy.
PRuvetSTAaYA
5
OYPROSTIYAOPECHATALSYAPRIVETSTASYA
0
helloworld
0
【题意】给你一个字符串,每一次操作可以将大写字母改成小写,反之亦然。问经过最少的操作数,使得此串的大写字母全部都在小写字母的左边。
【分析】感觉跟DP没啥关系,直接枚举...
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long LL;
const int N = 1e5+;
const int mod = 1e9+;
int n,a,b,k;
int dp[N],sum[N];
char str[N];
int main(){
scanf("%s",str);
int len=strlen(str);
for(int i=len-;i>=;i--){
sum[i]=sum[i+]+(str[i]>='a'?:);
}
int s=,ans=sum[];
for(int i=;i<len;i++){
s+=(str[i]>='a'?:);
ans=min(ans,sum[i+]+s);
}
printf("%d\n",ans);
return ;
}
Codeforces Round #116 (Div. 2, ACM-ICPC Rules) Letter(DP 枚举)的更多相关文章
- codeforces水题100道 第十八题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table (brute force)
题目链接:http://www.codeforces.com/problemset/problem/509/A题意:f[i][1]=f[1][i]=1,f[i][j]=f[i-1][j]+f[i][j ...
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和
E. Pretty Song time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table【递推】
A. Maximum in Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles
题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量 ...
- 递推水题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table
题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules)
Codeforces Round #116 (Div. 2, ACM-ICPC Rules) 代码 Codeforces Round #116 (Div. 2, ACM-ICPC Rules) A. ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) C. Letter 暴力
C. Letter Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/180/problem/C D ...
随机推荐
- Django ORM常用的函数以及修饰词
函数名称或修饰词 说明 filter() 返回符合指定条件的QuerySet exclude() 返回不符合指定条件的QuerySet ordey_by() 串接到QuerySet之后,针对某一指定的 ...
- COGS1882 [国家集训队2011]单选错位
★ 输入文件:nt2011_exp.in 输出文件:nt2011_exp.out 简单对比时间限制:1 s 内存限制:512 MB [试题来源] 2011中国国家集训队命题答辩 [问题 ...
- 【BZOJ】1588: [HNOI2002]营业额统计
[算法]平衡树(treap)||双向链表 [题解]treap知识见数据结构. #include<cstdio> #include<algorithm> #include< ...
- bufferd对象详解
使用buffer类处理二进制数据 在客户端javascript脚本代码中,对于二进制数据并没有提供一个很好的支持.然后在nodejs中需要处理像TCP流或文件流时,必须要处理二进制数据.因此在node ...
- C#编写程序监测某个文件夹内是否有文件进行了增,删,改的动作?
新建一个Console应用程序,项目名称为“FileSystemWatcher”,Copy代码进,编译后就可以用了.代码如下: using System; using System.Collectio ...
- 小程序_改变switch组件的大小
微信开发文档中,switch能修改颜色,没有直接修改switch大小的属性.用一般控件height & width来修改宽高是没有用的. 使用如下方法: 在.wxss文件: .wx-switc ...
- 【Python学习】程序运行完发送邮件提醒
有时候我们运行一个需要跑很长时间的程序,不管是在云主机还是本地主机上运行,我们都不可能一直守在电脑面前等.所以想到使用邮件来通知提醒. 示例代码如下 # -*- coding: utf-8 -*- # ...
- C#杂七杂八记录
1. 日期格式表示 DateTime.Now.ToString("yyyy-MM-dd") 2. div跟屏幕的高度一样高,自适应 <style> html, bo ...
- 修改VNCSERVER 默认的分辨率的方法
vi /usr/bin/vncserver /1024 找到默认的1024*768修改为 :1680*1050 reboot 重启
- SEO优化:WordPress站点地图(html和xml)插件Baidu Sitemap Generator
前阵子分享了<如何实现纯代码制作网站地图的html和xml版本>,不过不是每个人都喜欢用纯代码来折腾博客的.今天,boke112就给大家分享一款国人柳城制作的包含html和xml两个版本的 ...