B. Anatoly and Cockroaches

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 toalternate. 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.

思路:

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

swap操作可以通过取Min来实现。接下来只需要统计每种模式下,需要变换的在字母个数就行(r2b or b2r)

Code:

  

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector> using namespace std; const int Maxn = ;
char str[Maxn];
char str2[Maxn];
int main()
{
int n;
cin>>n;
scanf("%s",str);
int len = n, b2r = , r2b = , _b2r = , _r2b = ;
for(int i = ; i < len; i ++){
if(i % == ){
if(str[i] == 'r') r2b ++;
if(str[i] == 'b') b2r ++;
}else{
if(str[i] == 'r') _r2b ++;
if(str[i] == 'b') _b2r ++;
} }
cout<< min(max(r2b, _b2r), max(b2r, _r2b))<<endl;
return ;
}

【Codeforces】Codeforces Round #373 (Div. 2)的更多相关文章

  1. 【Codeforces】CF Round #592 (Div. 2) - 题解

    Problem - A Tomorrow is a difficult day for Polycarp: he has to attend \(a\) lectures and \(b\) prac ...

  2. 【二分】CF Round #587 (Div. 3)E2 Numerical Sequence (hard version)

    题目大意 有一个无限长的数字序列,其组成为1 1 2 1 2 3 1.......1 2 ... n...,即重复的1~1,1~2....1~n,给你一个\(k\),求第\(k(k<=10^{1 ...

  3. Codeforces Round #373 (Div. 2)A B

    Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 这回做的好差啊,a想不到被hack的数据,b又没有想到正确的思维 = = [题目链 ...

  4. Codeforces Round #373 (Div. 1)

    Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 题意 给一个长为\(n(n \le 2 \times 10^5)\)的小数,每次可以选 ...

  5. 【题解】Codeforces 961G Partitions

    [题解]Codeforces 961G Partitions cf961G 好题啊哭了,但是如果没有不小心看了一下pdf后面一页的提示根本想不到 题意 已知\(U=\{w_i\}\),求: \[ \s ...

  6. Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. 【Codeforces】Codeforces Round #551 (Div. 2)

    Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include &l ...

  9. 【codeforces】Codeforces Round #277 (Div. 2) 解读

    门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...

  10. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

随机推荐

  1. centos7安装个人网盘owncloud

    现在个人资料越来越重要,网络速度也已经满足日常需要,网盘已经是生活着存取个人数据不可缺少的工具. 下面在linxu centos7下面安装owncloud搭建自己私人网盘: 1.新建一个账号用来安装个 ...

  2. java归并排序

    代码如下: public class MergeSort { public static void mergeSort(DataWrap [] data) { sort(data , 0 , data ...

  3. Python基础-画菱形

    方法一 n = int(input('请输入:')) for i in range(1, n, 2): print(('*'*i).center(n)) for i in reversed(range ...

  4. 【Codeforces 225C】Barcode

    [链接] 我是链接,点我呀:) [题意] 让你把每一列都染成一样的颜色 要求连续相同颜色的列的长度都大于等于x小于等于y 问你最少的染色次数 [题解] 先求出每一列染成#或者.需要染色多少次 设f[0 ...

  5. chromeDriver下载地址

    http://chromedriver.storage.googleapis.com/index.html

  6. elasticsearch 权威指南Mapping(映射)

    什么是映射 类似于数据库中的表结构定义,主要作用如下: 定义Index下字段名(Field Name) 定义字段的类型,比如数值型,字符串型.布尔型等 定义倒排索引的相关配置,比如是否索引.记录pos ...

  7. centos7安装opennms-17.0.0

    https://blog.csdn.net/jiangzhexi/article/details/52036858 http://www.jb51.net/os/RedHat/281470.html

  8. [Node.js] Setup Local Configuration with Node.js Applications

    Github To stop having to change configuration settings in production code and to stop secure informa ...

  9. android 随手记之文件+參数上传请求

    第一步:须要两个jar的支持,稍后以下给会出下载地址. 第二步:建立一个project 以下贴出最基本的代码 package com.example.testpaizhao; import java. ...

  10. 如何杀掉(kill)Oracle中的会话(Session)

    Oracle中造成一些表被死锁或者会话异常退出,如执行了更新记录操作后,既没有commit也没有rollback,网络就断开了,也会造表或记录被锁住,待到超时后才会被解开,那样都会造成应用操作被阻塞. ...