B. Anatoly and Cockroaches

题目连接:

http://codeforces.com/contest/719/problem/B

Description

Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.

Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.

Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.

The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.

Output

Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.

Sample Input

5

rbbrr

Sample Output

1

Hint

题意

有n个字符,要么是r,要么是b,现在你想让他变成交替的

每次你可以修改一个字符,或者交换两个字符的位置。

问你最少花费是多少

题解:

水题,要么是rbrbrbrbrb这样,要么是brbrbrbrb这样

都判断一下取个最小就好了、

代码

#include<bits/stdc++.h>
using namespace std; string s;
int n,w1,w2,ans,ans1,ans2;
int main()
{
scanf("%d",&n);
cin>>s;
for(int i=0;i<n;i++)
{
if(i%2){if(s[i]!='r')w1++;}
else{if(s[i]!='b')w2++;}
}
ans=abs(w1-w2)+min(w1,w2);
w1=w2=0;
for(int i=0;i<n;i++)
{
if(i%2){if(s[i]!='b')w1++;}
else{if(s[i]!='r')w2++;}
}
ans=min(ans,abs(w1-w2)+min(w1,w2));
cout<<ans<<endl;
}

Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题的更多相关文章

  1. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  2. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  3. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  4. Codeforces Round #368 (Div. 2) A. Brain's Photos 水题

    A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...

  5. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  6. Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题

    A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...

  7. Codeforces Round #384 (Div. 2) A. Vladik and flights 水题

    A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...

  8. Codeforces Round #379 (Div. 2) D. Anton and Chess 水题

    D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play ...

  9. Codeforces Round #379 (Div. 2) B. Anton and Digits 水题

    B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...

随机推荐

  1. bzoj千题计划260:bzoj2940: [Poi2000]条纹

    http://www.lydsy.com/JudgeOnline/problem.php?id=2940 SG 博弈入门推荐张一飞的<由感性认识到理性认识 ——透析一类搏弈游戏的解答过程> ...

  2. bzoj千题计划201:bzoj1820: [JSOI2010]Express Service 快递服务

    http://www.lydsy.com/JudgeOnline/problem.php?id=1820 很容易想到dp[i][a][b][c] 到第i个收件地点,三个司机分别在a,b,c 收件地点的 ...

  3. SQL语句(十二)分组查询

    (十二)分组查询 将数据表中的数据按某种条件分成组,按组显示统计信息 查询各班学生的最大年龄.最小年龄.平均年龄和人数 分组 SELECT <字段名表1> FROM <表名> ...

  4. json转化数组

    //json格式数据 $data = '[{ "F_ModuleId": "1", "F_ParentId": "0", ...

  5. JavaScript——创建对象

    <script type="text/javascript"> //声明变量的首字母是小写 //1.对象字面量 /*var person = { name:" ...

  6. 升级Chrome后无法打开网页

    最近升级了网站,发现很多普通网站Chrome 都打不开了....  IE  可以正常打开,很是郁闷,重启电脑都不行. chrome://net-internals/#dns 点击如下按钮 清楚DNS缓 ...

  7. 修改MySQL的时区,涉及参数time_zone

    原地址:http://blog.csdn.net/mchdba/article/details/9763521 首先需要查看mysql的当前时区,用time_zone参数 mysql> show ...

  8. Vue零散知识点

    1.vue中的<router-view></router-view>的作用,它是和vue的路由相结合的,它的作用是将路由匹配到的组件渲染在里面.比如说你要跳转,如何没有< ...

  9. 修复 Tween.JS 的 onStop 设置无效

    Tween.js 个人认为还是一个比较不错的 缓动动画库,给作为学渣的我实现一些酷酷的动画带来了极大的遍历. 但是,今天突然发现特么设置onStop的回调函数居然没反应...... 作为一个渣渣只能一 ...

  10. 盒子模型与flex模型

    一.盒子模型 注意:两个相邻元素的margin值是重叠在一起的,取当中最大的那个值. 水平方向auto, margin:0 auto;会居中    但是margin-left:auto;,元素会到最右 ...