Codeforces Round #373 (Div. 2)-B. Anatoly and Cockroaches

来源:互联网 发布:标准差 知乎 编辑:程序博客网 时间:2024/06/01 22:06

原题链接

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 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
5rbbrr
output
1
input
5bbbbb
output
2
input
3rbr
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.


'r'和‘b'交替出现,就两种情况,第一个颜色要么是'r', 要么是'b', 算出变成这两种情况需要操作的次数,在求最小值

#include <bits/stdc++.h>#define maxn 200005#define MOD 1000000007using namespace std;typedef long long ll;char str[100005];int main(){//freopen("in.txt", "r", stdin);int n;scanf("%d%s", &n, str);int m = 'r' + 'b';int k1 = 'r', k2 = 'b';int r1 = 0, b1 = 0, r2 = 0, b2 = 0;for(int i = 0; str[i]; i++){if(k1 != str[i]){if(str[i] == 'r') r1++;else b1++;}if(k2 != str[i]){if(str[i] == 'r')  r2++;else b2++;}k1 = m - k1;k2 = m - k2;} cout << min(max(r1, b1), max(r2, b2)) << endl;return 0;}


0 0
原创粉丝点击