Coloring Colorfully
题目描述
N块瓦片从左到右排成一行。每个块的初始颜色由长度为N的字符串S表示。
如果S的第i个字符为0,则左边的第i个平铺将被漆成黑色,如果该字符为1,则漆成白色。
你想重新油漆一些瓷砖黑色或白色,使任何两个相邻的瓷砖有不同的颜色。
至少需要重新粉刷多少瓷砖才能满足条件?
Constraints
1≤|S|≤105
Si is 0 or 1.
输入
S
输出
样例输入
Copy
000
样例输出 Copy
1
提示
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
const int INF=0x3f3f3f3f;
const int maxn=5e5;
char a[maxn];
char b[maxn];
int sum[maxn];
int len;
void inint(){
scanf("%s",a+);
len=strlen(a+);
for(int i=;i<=len;i++){
b[i]=a[i];
}
}
int main(){
inint();
int ans1=;
for(int i=;i<=len;i++){
if(a[i]==''&&a[i-]==''){
a[i]='';
ans1++;
}
else if(a[i]==''&&a[i-]==''){
a[i]='';
ans1++;
}
}
int ans2=;
for(int i=len-;i>=;i--){
if(b[i]==''&&b[i+]==''){
b[i]='';
ans2++;
}
else if(b[i]==''&&b[i+]==''){
b[i]='';
ans2++;
}
}
printf("%d",min(ans1,ans2));
}
Coloring Colorfully的更多相关文章
- Atcoder Beginner Contest 124 解题报告
心态爆炸.本来能全做出来的.但是由于双开了Comet oj一个比赛,写了ABC就去搞那个的B题 还被搞死了. 回来写了一会D就过了.可惜比赛已经结束了.真的是作死. A - Buttons #incl ...
- Codeforces Round #369 (Div. 2)---C - Coloring Trees (很妙的DP题)
题目链接 http://codeforces.com/contest/711/problem/C Description ZS the Coder and Chris the Baboon has a ...
- CF149D. Coloring Brackets[区间DP !]
题意:给括号匹配涂色,红色蓝色或不涂,要求见原题,求方案数 区间DP 用栈先处理匹配 f[i][j][0/1/2][0/1/2]表示i到ji涂色和j涂色的方案数 l和r匹配的话,转移到(l+1,r-1 ...
- Codeforces Round #369 (Div. 2) C. Coloring Trees DP
C. Coloring Trees ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the pa ...
- CodeForces #369 C. Coloring Trees DP
题目链接:C. Coloring Trees 题意:给出n棵树的颜色,有些树被染了,有些没有.现在让你把没被染色的树染色.使得beauty = k.问,最少使用的颜料是多少. K:连续的颜色为一组 ...
- CodeForces 149D Coloring Brackets
Coloring Brackets time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- C. Coloring Trees DP
传送门:http://codeforces.com/problemset/problem/711/C 题目: C. Coloring Trees time limit per test 2 secon ...
- codeforces 711C C. Coloring Trees(dp)
题目链接: C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- POJ 1419 Graph Coloring(最大独立集/补图的最大团)
Graph Coloring Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4893 Accepted: 2271 ...
随机推荐
- win10下以管理员身份打开hosts文件
第一步: 第二步: 第三步:先后执行两个命令cmd notepad hosts 最后一步:在记事本中修改host文件
- java - GC垃圾收集器详解(三)
以前收集器的特点 年轻代和老年代是各自独立且连续的内存块 年轻代收集必须使用单个eden+S0+S1进行复制算法 老年代收集扫描整个老年代区域 都是以尽可能少而快速地执行GC为设计原则 G1是什么 G ...
- liunx 查找locate
使用 安装 yum install mlocate 更新数据库 updatedb 查找my.cnf文件 locate my.cnf
- layer.open获取弹出层的input框的值
使用top.$('#txtReason').val();获取值: //不通过 function unAuditData(id) { parent.layer.open({ type: , title: ...
- win10子系统ubuntu内的nginx启动问题
需用sudo启动,密码是windows密码.
- Spring Boot的Web配置
一.使用YML文件配置多套环境
- 【转载】17个新手常见Python运行时错误
转自:http://www.cnblogs.com/smile-ls/archive/2013/05/20/3088393.html 当初学 Python 时,想要弄懂 Python 的错误信息的含义 ...
- Mvc-WebAPI特性路由(自定义路由)Demo
Demo由VS2017编写. 1.先建一个WebApi项目 2.WebApiConfig.cs需要注册特性路由,config.MapHttpAttributeRoutes(); 3.项目默认有2个Co ...
- python笔记20(面向对象课程二)
今日内容 类成员 成员修饰符 内容回顾 & 补充 三大特性 封装 函数封装到类 数据封装到对象 * class Foo: def __init__(self,name,age): self.n ...
- HTML连载63-a标签的伪类选择器
一.a标签的伪类选择器 1.通过观察可以发现a标签存在一定状态 (1)默认状态,从未被访问过 (2)被访问过的状态 (3)鼠标长按的状态 (4)鼠标悬停在a标签上的演示 2.什么是a标签的伪类选择器? ...