Anatoly and Cockroaches

Windchill二次开发实战:手把手教你配置文档编号与名称的自动生成规则(附XML代码详解) 本文详细介绍了Windchill二次开发中配置文档编号与名称自动生成规则的实战指南。通过XML代码详解,帮助开发者掌握初始化规则的配置技巧,包括三种编号生成模式(手动输入、自动生成可编辑、自动生成只读)和名称自动同步的进阶配置,提升PLM系统实施效率。 阅读详情

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

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这样

如当为rbrbrbrb的时候其实可以写成两部分r_r_r_和_b_b_b_b,记录下应该为b但是却为r的个数,应该为r却为b 的个数。这样看看两个个数哪个小,那么小的那个个数一定可以通过交换使得序列符合条件,因为每次交换使得两个字母符合,所以个数多的那个也相应的完成一部分匹配,例如w1 = 5,w2 = 2;所以可以交换两个,那么交换后w1中的两个也完成了匹配,所以w1中就剩下3个,只能通过修改使得符合条件。即abs(w1-w2)+min(w1,w2)。

两种情况都判断一下取个最小就好了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
int n,w1,w2,ans,ans1;
string s;
int main(){
    scanf("%d",&n);
    cin>>s;
    int i;
    for(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(i = 0; i < n; i++){
        if(i%2){
            if(s[i]!='b')w1++;
        }
        else{
            if(s[i]!='r')w2++;
        }
    }
    ans1 = abs(w1-w2)+min(w1,w2);//同理
    ans = min(ans,ans1);
    cout << ans << endl;
    return 0;
}

、

反光柱定位算法实战03:VEnus代码解析和纯反光柱定位中的可改进方向 本文深入解析了开源框架VEnus的反光柱定位与建图实现流程,包括强度提取、聚类、数据关联、位姿优化等核心模块。同时指出其三大局限:匹配质量脆弱性、单一传感器依赖和地图扩展逻辑缺失,并提出改进方向:融合里程计/IMU数据、引入图优化后端、建立动态地图维护机制。该分析为基于反光柱的定位系统优化提供了实用参考,有助于提升工业场景下的定位鲁棒性和精确性。 阅读详情

相关推荐

使用 Cadence ams 仿真器 对 混合信号电路 进行仿真

文章目录Cadence 基于ams仿真器的混合信号电路仿真建立数字(Digital)模块建立 Analog - Digital 混合仿真原理图建立 Analog - Digital 混合仿真config文件配置混合信号电路仿真环境针对混合信号电路demo进行仿真 Cadence 基于ams仿真器的混合信号电路仿真 你好,这里是一篇关于使用 Cadence 软件通过 ams 仿真器对混合信号电路(D...

mymatin1004的博客 2万+

CodeForces - 719B 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 co

xxtz_xt的博客 414

[CARLA系列--01]CARLA 0.9.15 在Windows下的安装教程(一)

Carla是一款开源的自动驾驶仿真器,它基本可以用来帮助训练自动驾驶的所有模块,包括感知系统,Localization, 规划系统等等.Carla这个产品目前已经更新到了最新的0.9.15版本,目前遇到好多人在windows系统上如何安装可编辑版的Carla遇到了好多问题,所以针对在windows上的安装,推出此列教程.

汽车ECU自动化测试 4650

Codeforces 719B B. Anatoly and Cockroaches

B. Anatoly and Cockroachestime limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard outputAnatoly lives in the university dorm as many other students do. As you

ISMDEEP 801

经典算法之——解决全排列问题以及详解

回溯”指的是“状态重置”,可以理解为“恢复现场”,是在编码的过程中,是为了节约空间而使用的,而在递归或者深度优先中根据需要的场合来配合回溯法可以进一步对自己的代码进行优化。, n-1, n},方向都为向左。邻位对换法是全排列生成算法中的其中一种,它的换位是双向的,通过保存数字的“方向性”来快速得到下一个排列。最后以 3 开头的全排列为[3, 1, 2], [3, 2, 1];以 1 开头的全排列为[1, 2, 3], [1, 3, 2];以 2 开头的全排列为[2, 1, 3], [2, 3, 1];

m0_68987535的博客 8794

01 Aras Innovator二次开发实战:从IOM到AML的完整交互指南

本文详细介绍了Aras Innovator二次开发实战,从IOM到AML的完整交互指南。通过JavaScript和C#代码示例,展示了如何在客户端和服务端使用IOM进行开发,并深入解析AML语言的基础语法和调试技巧。文章还提供了文档管理和BOM管理等典型场景的实战案例,帮助开发者快速掌握Aras Innovator二次开发的核心技术。

wind6的博客 650

csust-8.6早训CF之700-2000分

目录 A - Anatoly and Cockroaches B - Efim and Strange Grade C - One-dimensional Japanese Crossword D - Passwords E - Journey F - Maxim and Array A - Anatoly and Cockroaches CodeForces - 7...

孤风的博客 544

STM32F103C8T6实战:从零搭建三相SPWM逆变器(附MATLAB仿真、PCB、源码)

本文详细介绍了如何使用STM32F103C8T6单片机从零搭建三相SPWM逆变器,涵盖硬件选型、PCB设计、SPWM算法实现及MATLAB仿真。项目提供完整的工程文件,包括源码、PCB设计和仿真模型,适合电子工程师和学生进行实践学习。通过本教程,读者可以掌握逆变器设计的核心技术和调试方法。

weixin_30458043的博客 451

Codeforces--719B--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 ar...

猩猩是个好程序员的博客 190

[附源码]计算机毕业设计Python财务管理系统(程序+源码+LW文档)

该项目含有源码、文档、程序、数据库、配套开发软件、软件安装教程项目运行环境配置:Pychram社区版+py项目技术:django + python+ Vue 等等组成,B/S模式 +pychram管理等等。环境需要1.运行环境:最好是python3.7.7,我们在这个版本上开发的。其他版本理论上也可以。2.pycharm环境:pycharm都可以。推荐pycharm社区版;3.mysql环境:建议是用5.7版本均可。

巧灵计算机程序设计 1067

【深度学习】最强算法之:残差网络(ResNet)

一篇掌握深度学习算法之:残差网络

商务合作 | 面试培训 | 职场规划 ==>主页扫码 7837

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

无知的我 1042

三菱FX5U-PLC建立CClink的IO通讯

最新需要用三菱的FX5U的PLC搭建一个CClink通讯,PLC做主站,控制CClink从站的IO,下面2个输入模块AJ65SBTB1-32D,两个输出模块AJ65SBTB1-32T。3、在右侧的部件,选择网络模块:FX5-CCL-MS,CC-link主站模块。依次把加入两个AJ65SBTB1-32D,两个AJ65SBTB1-32T。7、基本设置,网络配置设置,链路刷新设置,设置好下面参数,应用。6、基本设置,网络配置设置,CC-Link配置设置。8、部件选择,模块,右键,添加模块标签。

wzz418550729的博客 999

Codeforces Round #373 (Div. 2) Anatoly and Cockroaches —— 贪心

题目链接:http://codeforces.com/contest/719/problem/B B. Anatoly and Cockroaches time limit per test 1 second memory limit per test 256 megabytes input standard input out...

weixin_30564901的博客 65

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

[codeforces] B - Anatoly and Cockroaches 贪心

B - Anatoly and Cockroaches Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Anatoly lives in the university dorm as many other

你那么爱笑,家里人知道吗? 678

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces 719B Anatoly and Cockroaches

参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6415496.html B. Anatoly and Cockroaches time limit per test:1 second memory limit per test:256 megabytes input:standard input output...

weixin_30394251的博客 178

A - Anatoly and Cockroaches CodeForces - 719B

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

tomjobs的博客 408

codeforces 719B:Anatoly and Cockroaches

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

dgoh41514的博客 192

Codeforces 719B Anatoly and Cockroaches【思维】

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 man

mengxiang000000 462

【31.58%】【codeforces 719B】 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...

AWCXV 131

Codeforces 719B-Anatoly and Cockroaches

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

sdljtyk的博客 275

cf--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 co

扬帆起航 544

CodeForces - 719B (Anatoly and Cockroaches) 思维题

题意:每次操作可换掉一只蟑螂的颜色,或者交换两只蟑螂的位置以达到交替出现不同颜色,求最小操作数。 #include<cstdio> #include<cstring> #include<algorithm> #include<math.h> using namespace std; //最终的串要么为rbrbrbr...型,要么为brbrbrbr.....

weixin_44756457的博客 192
上一篇: C Looooops(扩展欧几里得)
下一篇: Complete the Word(暴力)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值