B. Anatoly and Cockroaches

题目连接:

http://codeforces.com/contest/719/problem/B

Description

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.

Sample Input

5

rbbrr

Sample Output

1

Hint

题意

有n个字符,要么是r,要么是b,现在你想让他变成交替的

每次你可以修改一个字符,或者交换两个字符的位置。

问你最少花费是多少

题解:

水题,要么是rbrbrbrbrb这样,要么是brbrbrbrb这样

都判断一下取个最小就好了、

代码

#include<bits/stdc++.h>
using namespace std; string s;
int n,w1,w2,ans,ans1,ans2;
int main()
{
scanf("%d",&n);
cin>>s;
for(int i=0;i<n;i++)
{
if(i%2){if(s[i]!='r')w1++;}
else{if(s[i]!='b')w2++;}
}
ans=abs(w1-w2)+min(w1,w2);
w1=w2=0;
for(int i=0;i<n;i++)
{
if(i%2){if(s[i]!='b')w1++;}
else{if(s[i]!='r')w2++;}
}
ans=min(ans,abs(w1-w2)+min(w1,w2));
cout<<ans<<endl;
}

Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题的更多相关文章

  1. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  2. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  3. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  4. Codeforces Round #368 (Div. 2) A. Brain's Photos 水题

    A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...

  5. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  6. Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题

    A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...

  7. Codeforces Round #384 (Div. 2) A. Vladik and flights 水题

    A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...

  8. Codeforces Round #379 (Div. 2) D. Anton and Chess 水题

    D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play ...

  9. Codeforces Round #379 (Div. 2) B. Anton and Digits 水题

    B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...

随机推荐

  1. bzoj千题计划178:bzoj2425: [HAOI2010]计数

    http://www.lydsy.com/JudgeOnline/problem.php?id=2425 题意转化: 给定一个集合S,求S的全排列<给定排列 的排列个数 从最高位开始逐位枚举确定 ...

  2. elementUI 表格分页后台排序记录

    表格代码 <div class="m-table"> <el-table :data="logs" style="width: 10 ...

  3. 被误解的 Node.js

    http://www.ibm.com/developerworks/cn/web/1201_wangqf_nodejs/ 被误解的 Node.js

  4. TED_Topic8:How to control someone else's arm with your brain

    By Greg Gage (Neuroscientist) Greg Gage is on a mission to make brain science accessible to all. In ...

  5. Fiddler抓取HTTPS最全(强)攻略

    本文来自于柠檬班49期学员superman童鞋的学习笔记.希望对同样是测试萌新的你有帮助,如果觉得好,可以点个赞噢~ 对于想抓取HTTPS的测试初学者来说,常用的工具就是fiddler.可是在初学时, ...

  6. J - FatMouse's Speed dp

    题目链接: https://vjudge.net/contest/68966#problem/J 找最长子串并且记录路径. TLE代码: #include<iostream> #inclu ...

  7. 利用Python生成随机密码

    #coding:utf-8 #利用python生成一个随机10位的字符串 import string import random import re list = list(string.lowerc ...

  8. umount /mnt/cdrom

    这是因为有程序正在访问这个设备,最简单的办法就是让访问该设备的程序退出以后再umount.可能有时候用户搞不清除究竟是什么程序在访问设备,如果用户不急着umount,则可以用: umount -l / ...

  9. apache显示目录文件列表

    在apache服务器下访问一个目录,如果没有index.html/index.php,则会报错. 为了访问文件夹: 1. 在 /var/www/html 目录下新建 /d/ mkdir d 2.  t ...

  10. PhpStorm,Pycharm,Goland破解

    phpstorm是一个轻量级且便捷的PHP IDE,其旨在提供用户效率,可深刻理解用户的编码,提供智能代码补全,快速导航以及即时错误检查.不但是php开发的利器,前端开发也是毫不逊色的.下面记录Php ...