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. 接口测试Case之面向页面对象编写规范

    一.什么是页面对象化 主要提倡的思想是:万物皆对象,即把一个Page看成一个对象,来进行接口自动化Case的编写,不要闲扯,直接讲怎么个操作法呢? 二.有什么优势? 2.1 Case层次清晰,便于管理 ...

  2. 转----MarkdownPad2.5 注册码

    经测试可用 User: Soar360@live.com 授权: GBPduHjWfJU1mZqcPM3BikjYKF6xKhlKIys3i1MU2eJHqWGImDHzWdD6xhMNLGVpbP2 ...

  3. 8 Productivity hacks for Data Scientists & Business Analysts

    8 Productivity hacks for Data Scientists & Business Analysts Introduction I was catching up with ...

  4. Jquery教你写一个简单的轮播.

    这个我表示写的不咋地-_-//,但是胜在简单,可优化性不错. 实际上我本来想写个复杂点的结构的,但是最近忙成狗了!!!!所以大家就讲究着看吧 HTML结构 <div class="ba ...

  5. 一些javascript的工具书

    http://pan.baidu.com/s/1jGj9CvO

  6. CSS 编码中超级有用的工具集合

    当你开发网站和 Web 应用时,使用合适的工具可以节省大量的时间.本文我将收集一些非常有用的 CSS 编码工具,希望对你有帮助. Pure CSS Pure 是来自雅虎的 CSS 框架,使用 Norm ...

  7. Request.Cookies 和 Response.Cookies 的区别

    .NET中提供了读写Cookie的多种方法,Request.Cookies 是客户端通过 Cookie 标头形式由客户端传输到服务器的 Cookie:Response.Cookies 在服务器上创建并 ...

  8. RabbitMQ Queue一些常见模式

    懒队列:lazy Queue,即用到的时候才会加载,3.6.0及之后新添加的.当新添加数据后,不会将其放入到内存中,而是将其放入到磁盘中. 普通队列:1).in-memory,数据直接放入到内存中. ...

  9. Bug Bounty Reference

    https://github.com/ngalongc/bug-bounty-reference/blob/master/README.md#remote-code-execution Bug Bou ...

  10. git merge branch to master

    git checkout master git pull git merge testbranch git push