B. Anatoly and Cockroaches
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

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.

Examples
Input
5

rbbrr
Output
1
Input
5

bbbbb
Output
2
Input
3

rbr
Output
0
Note

In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.

In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.

In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.

题目链接:http://codeforces.com/problemset/problem/719/B

分析:细想只有两种模式,一种brbrbr... 另一种rbrbrb... 只需要统计这两种模式下,需要的两种操作数中最小的一个,即是答案。

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
const int MAXN = ;
char a[MAXN];
int main()
{
int n;
while(cin>>n)
{
scanf("%s",a);
int m = ;
int t=;
int u=;
int v=;
for(int i=; i<n; i++)
{
if(i%==)
{
if(a[i]=='r')
m++;
if(a[i]=='b')
t++;
}
else
{
if(a[i]=='r')
u++;
if(a[i]=='b')
v++;
}
}
int x=max(t,u);
int y=max(m,v);
int z=min(x,y);
printf("%d\n",z);
}
return ;
}

Codeforces 719B Anatoly and Cockroaches的更多相关文章

  1. Codeforces 719B Anatoly and Cockroaches(元素的交叉排列问题)

    题目链接:http://codeforces.com/problemset/problem/719/B 题目大意: 有一队蟑螂用字符串表示,有黑色 ‘b’ 和红色 'r' 两种颜色,你想使这队蟑螂颜色 ...

  2. CodeForces 719B Anatoly and Cockroaches 思维锻炼题

    题目大意:有一排蟑螂,只有r和b两种颜色,你可以交换任意两只蟑螂的位置,或涂改一个蟑螂的颜色,使其变成r和b交互排列的形式.问做少的操作次数. 题目思路:更改后的队列只有两种形式:长度为n以r开头:长 ...

  3. CodeForces 719B Anatoly and Cockroaches (水题贪心)

    题意:给定一个序列,让你用最少的操作把它变成交替的,操作有两种,任意交换两种,再就是把一种变成另一种. 析:贪心,策略是分别从br开始和rb开始然后取最优,先交换,交换是最优的,不行再变色. 代码如下 ...

  4. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

  5. Codeforces Round #373 (Div. 2) Anatoly and Cockroaches —— 贪心

    题目链接:http://codeforces.com/contest/719/problem/B B. Anatoly and Cockroaches time limit per test 1 se ...

  6. B. Anatoly and Cockroaches

    B. Anatoly and Cockroaches time limit per test 1 second memory limit per test 256 megabytes input st ...

  7. codeforces 719B:Anatoly and Cockroaches

    Description Anatoly lives in the university dorm as many other students do. As you know, cockroaches ...

  8. 【31.58%】【codeforces 719B】 Anatoly and Cockroaches

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  9. Anatoly and Cockroaches

    Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also li ...

随机推荐

  1. iOS开发——代理与block传值

    一.代理传值的方法 1.Hehe1ViewController.h中 #import <UIKit/UIKit.h> @protocol Hehe1ViewControllerDelega ...

  2. [noip2013]货车运输(kruskal + 树上倍增)

    描述 A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物,司机们想知道每辆车在不超过车辆限重的情况下,最多能运多 ...

  3. IOS开发中UIAlertController(警告框)的使用

    步骤一.初始化: UIAlertController * inputname = [UIAlertController alertControllerWithTitle:@"未输入账户&qu ...

  4. SQLite用法

    SQLite语法:http://blog.csdn.net/ejzhang/article/details/6224915#08 SQLite查询优化:1.http://www.eoeandroid. ...

  5. GP项目总结(一)

    1.使用activity渲染不同的View时,两种方法: (1.)自定义两个不同的View,然后在mainActivity里根据不同的数据使用不同的View,通过addView()来Activity里 ...

  6. java--反射和注解

    一.java.lang.reflect类   Class类 1.反射机制(Reflection):通过类创建对象, 2.反射机制提供了如下功能: 在运行时,判断任意一个对象所属的类 构造任意一个类的对 ...

  7. Xcode7中 添加 .dylib

    转一个 Xcode 7 缺少 *.dylib库的解决方法 Xcode7中 Link Binary With Libraries 没有 .dylib库,只能找到对应的 .tbd,但不能代替使用,通过查找 ...

  8. c# 正则表达式的用户

    Regex emailregex = new Regex("(?<user>[^@]+)@(?<host>.+)"); if(emailregex.IsMa ...

  9. python 自动化之路 day 14

    今日内容 http://www.cnblogs.com/wupeiqi/articles/5699254.html 群共享 s15Html课件 1. paramiko模块 https://github ...

  10. error: WatchKit App doesn't contain any WatchKit Extensions whose WKAppBundleIdentifier matches

    error: WatchKit App doesn't contain any WatchKit Extensions whose WKAppBundleIdentifier matches &quo ...