CF719B.Anatoly and Cockroaches

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

阿纳托利和许多其他学生一样,住在大学宿舍里。众所周知,蟑螂也和学生们一起生活在宿舍中。蟑螂可能有两种颜色:黑色和红色。阿纳托利的房间里共有 nn 只蟑螂。

阿纳托利刚刚让所有蟑螂排成了一列。由于他是个完美主义者,他希望这一列中蟑螂的颜色交替出现。他有一罐黑色油漆和一罐红色油漆。在一次操作中,他可以执行以下两种动作之一:交换任意两只蟑螂的位置,或者选取任意一只蟑螂并改变其颜色。

请帮助阿纳托利计算出,使蟑螂颜色在队列中交替出现所需的最少操作次数。

输入格式

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.

输入的第一行包含一个整数 nn(1 ≤ n ≤ 100 0001 ≤ n ≤ 100\,000)—— 蟑螂的数量。

第二行包含一个长度为 nn 的字符串,由字符 'b' 和 'r' 组成,分别表示黑色蟑螂和红色蟑螂。

输出格式

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.

输出一个整数——Anatoly 为使蟑螂队列的颜色交替所需执行的最少操作次数。

输入输出样例

  • 输入#1

    5
    rbbrr

    输出#1

    1
  • 输入#2

    5
    bbbbb

    输出#2

    2
  • 输入#3

    3
    rbr

    输出#3

    0

说明/提示

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.

在第一个样例中,阿纳托利需要交换第三只和第四只蟑螂。他完成此操作需要 1 步。

在第二个样例中,最优方案是将第二只和第四只蟑螂涂成红色。这需要 2 步。

在第三个样例中,队列中蟑螂的颜色已经交替排列,因此答案为 0。

输入解题思路,AI测评打分。不知道怎么写?

首页