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 ...
随机推荐
- .net mvc中epplus导出excel
帮助类 using OfficeOpenXml; using OfficeOpenXml.Style; using System; using System.Collections.Generic; ...
- python3练习100题——049
题目:使用lambda来创建匿名函数. sum=lambda x,y:x+y from functools import reduce reduce(sum,[1,2,3,4,5])
- vue router的其他属性、 值的传递 、 懒加载
路由的router-link标签有几个其他属性: 路由可以传递值(一般用作条目的id传递,之后用这个id从axios获取页面显示的数据 第一步: 定义路由以及值的属性名称(之后在跳转路由后页面里面获取 ...
- windows中Read函数引发数据异常的问题
[摘要] 在Window C/S开发中少不了客户端与服务端数据通信的情况,每当客户端从服务端获取数据时会将数据读到本地本件或缓存中,例如通过CInternetFile类的Read函数会将网卡缓存中的数 ...
- JavaScript权威指南第6版
描述网页内容的html,描述网页样式的css,描述网页行为的JavaScript js,适合面向对象和函数式编程风格 es5新特性 第二章 词法结构 1.JavaScript程序是用Unicode字符 ...
- BSGS求解离散对数问题
离散对数问题是求解axΞb mod(n) 同余方程 以下模板使用于gcd(a,n)=1的情况 ; int hs[mod],head[mod],Next[mod],id[mod],top; void i ...
- canvas-文字粒子化(小程序)
有2张画板,1张渲染文字为获取文字数组,另一张用来渲染粒子根据拿到的数组. step1:渲染文字,根据canvasGetImageData拿到rgba数组 step2:遍历rgba数组拿到粒子的坐标 ...
- python接口自动化-requests-toolbelt处理multipart/form-data
1.requests-toolbelt官方文档:https://pypi.org/project/requests-toolbelt/ 2.环境安装 pip install requests-tool ...
- PP: Shallow RNNs: a method for accurate time-series classification on tiny devices
Problem: time series classification shallow RNNs: the first layer splits the input sequence and runs ...
- jquery tagsinput监听输入、修改、删除事件
个人博客 地址:http://www.wenhaofan.com/article/20181118192458 由于度娘上的根本搜不到对应的操作,连该插件对应的文档介绍都没有,不得已debug了源码才 ...