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. 《玩转Bootstrap(JS插件篇)》笔记

    导入JavaScript插件 不论是单独导入还一次性导入之前必须先导入jQuery库. 一次性导入 <script src="js/bootstrap.min.js"> ...

  2. Python 线程池的实现

    import urllib2 import time import socket from datetime import datetime from thread_pool import * def ...

  3. Compilation err ororg.eclipse.jdt.internal.compiler.classfmt.ClassFormatException

    严重: Compilation errororg.eclipse.jdt.internal.compiler.classfmt.ClassFormatExceptionat org.eclipse.j ...

  4. iOS 之 后台下载,前台显示模式,双 block

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //耗时的操作 NSURL *url ...

  5. C++中的输入参考

    1.输入输出 1)operator>> 参考:cplusplus.com Extracts characters from is and stores them in s as a c-s ...

  6. 如何测试LBS功能

    在LBS功能的开发中,为了保证通用性,服务器存在的坐标是基于wgs84的,这个通常由GPS设备传过来,对于PC来说,如何获得这个值呢?可以利用Google Earth来获得,并修改显示的坐标系统,“工 ...

  7. 关于异常“The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine”的处理

    我们在利用SqlBlukcopy技术倒2010 或者2007格式的文件到SqlServer 数据库的时候,会发生如下错误: 原因如下: 1.在用SQL SERVER 2005访问.xlsx文件(off ...

  8. Clojure发音

    Clojure的发音和单词closure是一样的.Clojure之父是这样解释Clojure名字来历的 “我想把这就几个元素包含在里面: C (C#), L (Lisp) and J (Java). ...

  9. table固定前两列和最后一列,其他滑动显示

    网上搜的基本都是4个table做的,数据处理比较麻烦,写了个一个table的,此示例只固定了前两列和最后一列,和网上的不太一样. 网上搜的基本都是4个table做的,数据处理比较麻烦,写了个一个tab ...

  10. 支付宝 Android 版使用的开源组件

    支付宝 Android 版使用的开源组件 前言: 花了点时间整理了 支付宝 Android 客户端使用的开源组件,给需要的同学.在你不知道用什么开源框架的时候可以作下参考,毕竟支付宝是阿里的重量级产品 ...