Codeforces Round #442 (Div. 2) B - Nikita and string

欧姆龙NX控制器与Sysmac studio的电机配置方法 使用歐姆龍NX控制器與Sysmac studio控制電機簡單運動 <上> — 環境配置0. 前言1. 實際硬件連接2. Sysmac studio 配置2.1 新建工程2.2 通信設置2.2.1 軟件內通信設置2.2.2 上位機本地通信設置 0. 前言 筆者最近需要使用到歐姆龍的多軸運動控制器來控制電機運動,但網路上關於Sysmac studio的教程或文章較為零散,作為初學者的筆者難以消化,故在稍微會用軟件後撰寫本文,為自己留個筆記,同時希望能夠幫助到需要的人。 1.本文面向買了歐姆龍控制器 阅读详情
B. Nikita and string
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

One day Nikita found the string containing letters "a" and "b" only.

Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".

Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?

Input

The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".

Output

Print a single integer — the maximum possible size of beautiful string Nikita can get.

Examples
input
abba
output
4
input
bab
output
2
Note

It the first sample the string is already beautiful.

In the second sample he needs to delete one of "b" to make it beautiful.

题意 给出一个只包含a,b 的字符串,可以删除任意数量的字符(不可调换位置),使得ABA的形式的字符串最长(A代表若干个a,B代表若干个b)

求出a,b的前缀和,遍历一遍i,j之间b的个数,找出最大长度

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
	char s[5005];
	int a[5005] = {0}, b[5005] = {0};
	scanf("%s", s + 1);
	int l = strlen(s + 1), A = 0, B = 0, sum = 0;
	for (int i = 1; i <= l; i ++) {
		b[i] = s[i] == 'b' ? b[i - 1] + 1 : b[i - 1];
		a[i] = s[i] == 'a' ? a[i - 1] + 1 : a[i - 1];
	}
	for (int i = 1; i <= l; i ++) {
		for (int j = i - 1; j <= l; j ++) {
			if (a[i - 1] + b[j] - b[i - 1] + a[l] - a[j] > sum) {
				sum = a[i - 1] + b[j] - b[i - 1] + a[l] - a[j];
			}
		}
	}
	printf("%d\n", sum);
}


【100%通过率】2023华为od机试C卷【螺旋数组矩阵】C++ 实现 给出数字个数n和行数m(1 < n,m < 999),从左上角的1开始,按照顺时针螺旋向内写方式,依次写出2,3...n,最终形成个一m行矩阵。疫情期间,小明隔离在家,百无聊赖,在纸上写数字玩。输入一行,两个整数,空格隔开,依次表示n、m。4.数字不够时,使用单个*号占位。3.填充数字时优先填充外部。1:模拟整个过程打印即可。1.每行数字的个数一样多。小明对这个矩阵有些要求。2.列的数量尽可能少。 阅读详情

相关推荐

单细胞分析实战:当Seurat的SCTransform遇上Harmony,我的整合流程优化笔记

本文详细介绍了单细胞转录组数据分析中SCTransform与Harmony整合流程的优化策略。通过实战案例展示如何调整SCTransform参数、优化Harmony整合效果,并解决常见问题,帮助研究者获得更可靠的生物学发现。特别适合需要处理批次效应的单细胞数据分析人员。

weixin_42552716的博客 357

Codeforces Round #442 (Div. 2) B.Nikita and string

双指针方法 以前立志要跟鸡老师学dp,结果中途而废。隔了三个月然后这道1500的dp做不出来。。。 题目链接:http://codeforces.com/contest/877/problem/B 思路:存a和b的前缀数目。 那我们可以枚举所有中间区间[i,j] a:[0-i] b:[i-j] a:[j-n] 把每个区间对应的值加起来。取最大值!妙啊! #include <bits/stdc...

Alex Panda的博客 252

汽车底盘技术解析:从悬架调校到智能化,如何评价国产车底盘实力

汽车底盘作为决定车辆驾驶质感、安全性和耐久性的核心系统,其技术内涵远不止于悬架结构。从行驶系、转向系到制动系的协同工作,底盘调校是一门融合机械原理与工程实践的艺术。在电动化与智能化浪潮下,底盘技术正经历从被动适应到主动响应的变革,CDC可变阻尼减震器和空气悬架等技术的应用,让底盘具备了通过OTA升级实现性能优化的可能。国产汽车品牌如奇瑞、吉利等,通过平台化架构研发与调校经验积累,正推动底盘技术从“能用”向“好用”乃至“塑造独特驾驶风格”迈进。理解底盘技术,需超越简单的结构对比,关注其在实际路况中的滤震性、支

weixin_34413103的博客 384

【Codeforces Round #442 (Div. 2) B】Nikita and string

【链接】 我是链接,点我呀:) 【题意】 在这里输入题意 【题解】 枚举中间那一段从哪里开始、哪里结束就好 注意为空的话,就全是a. 用前缀和优化一下。 【代码】 #include <bits/stdc++.h> using namespace std; const int N = 5e3; string s; int a[N+10],pre[N+10...

AWCXV 123

一种导弹追踪算法的MATLAB仿真实现

以下是一个用于模拟机动变轨导弹和防空导弹追踪过程的 MATLAB 代码,同时会提供 3D 效果展示。你可以运行这段代码,从而观察机动变轨导弹和防空导弹的速度与位置变化。

SmartGridequation的博客 933

Ubuntu系统下主板GPU温控pwm风扇

在Linux系统下——以Ubuntu为例,配置主板sys_fan等接口连接pwm温控风扇转速根据NVIDIA GPU温度,为服务器GPU等无主动散热显卡提供散热。

罗思哲的博客 5032

Codeforces Round #442 (Div. 2) B. Nikita and string

题意:求最长可以分a b a为三部分子串,a b a可以为空 思路在代码里 1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #define...

176

【腾讯小龙虾WorkBuddy专栏01】初识WorkBuddy!定位、核心优势、功能界面全解析

【腾讯小龙虾WorkBuddy专栏01】初识WorkBuddy!定位、核心优势、功能界面全解析

AI人人懂 3819

【Codeforces Round #442 (Div. 2)】 B. Nikita and string (线性状态dp)

线性dp入门题, 也可以枚举区间来做。题意:一个5000的字符串,只有a,b两个字符,现在可以可以删一下字符,使得剩下的字符可以裁剪成三段,第一段和第三段只含a,第二段只含b。问删除后的字符串最长可以是多长。

hmc0411的博客 1694

深度学习论文: Towards Total Recall in Industrial Anomaly Detection

在大规模工业制造中,能够准确检测出有缺陷的零件至关重要。我们在这项工作中面临的一个特殊挑战是冷启动问题:仅使用正常的示例图像来训练模型。虽然可以针对每个类别手动设计解决方案,但我们的目标是构建能够自动适用于多个任务的系统。最佳的方法是将ImageNet模型的嵌入特征与异常检测模型结合起来。在本文中,我们在这一研究基础上进行了扩展,并提出了PatchCore,它利用了一个具有最大代表性的正常补丁特征内存库。通过这种方法,我们能够更好地解决冷启动问题,并提高系统在多任务上的性能。

mingo_敏 1875

【深度解析TI InstaSPIN】无传感器FOC控制的核心方案

TI InstaSPIN通过“自动识别+通用观测器+开源工具链”的组合,解决了无传感器FOC控制开发难度大、周期长的核心痛点。其核心优势在于快速统一软件观测器的通用性与高精度,以及Fly Start闭环零速启动策略的高可靠性,可适配空调压缩机等家电电机的复杂运行需求。在空调外机双电机控制场景中,InstaSPIN与TI C2000系列MCU(F280013x/F28E12x)完美契合,借助MCU的高性能DSP内核与丰富外设,可实现双电机的精准同步控制,同时降低硬件成本与开发周期。

昔时扬尘处 322

Codeforces Round #442 (Div. 2) B. Nikita and string

把一个字符串通过删去一些字符分成x*a+y*b+z*a的形式,问这个字符串最长几个字符

AC__GO的博客 525

java零基础从入门到精通(全)

目录前言1. 入门知识1.1 java体系1.2 JDK/JRE/JVM区别1.3 编译与运行理解1.4 类体函数细节2. 标识符 前言 java优势 健壮性(JVM(C++语言写的一个虚拟的计算机)、GC(垃圾回收机制)) 多线程并发 可移植性/跨平台 1. 入门知识 1.1 java体系 JavaSE:标准版 JavaEE:企业版 JavaME:微型版 1.2 JDK/JRE/JVM区别 JVM是不能独立安装的。 JRE和JDK都是可以独立安装的 层层嵌套,jvm包括jdk,jdk包括jre

码农研究僧的博客 6万+

Codeforces Round #442(Div.2) B.Nikita and string(线性DP)

题目链接:Nikita and string 题意:给出一个长度<=5000的a-b串,允许移除串的某些字符,其他字符的相对位置不变,使得串能被切割成三个子串S1,S2,S3,满足S1、S3只含字符a或者为空,S2只含字符b或者为空。问移除字符过后的串的长度最大为几? 题解:我采用DP做法,目标求长度最长,在满足要求的条件下。设置状态:开大小为dp[5010][3]的数组,dp[i][0]表示第

ganzibang 402

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

Codeforces Round #442 (Div. 2)--B. Nikita and string--前后缀和思维

B. Nikita and string time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Nikita found the string containing letters "a" and "...

lanshan1111的博客 182

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Codeforces Round #442 (Div. 2) A. Alex and broken contest,B - Nikita and string

A. Alex and broken contest time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output One day Alex was creating a contest about his friends, but acci

NITjianbagengmu的博客 449

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces Round #442 (Div. 2) B. Nikita and string (记忆化搜索)

cf晚间档一反常态,B和C交换了难度,真是有趣。 记忆化搜索,3种状态,暴力的搜一下,没想到这么做。还是道行不够。 -----------------因为热爱,所以执着----------------------- #include using namespace std; #define pb push_back #define mp make_pair char s[50

但求心安的博客 347

Codeforces Round #442 (Div. 2)B. Nikita and string(字符串,贪心)

B. Nikita and string time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Nikita found the string contai

WhaleFall 304

Alex and broken contest Codeforces Round #442

本来按计划昨天是要更新博客的。。不过这两天实在很忙,要准备电路的考试,而且昨天巨忙。。。 这是昨天写的一道题,很简单,题目容易理解直接调用C++里面的string的find函数就能处理的很好 不过以前学的那些STL知识。。。不用就忘了很多。 这道题里面的find函数里面传入了两个参数,就是说从s的下标index开始进行查询string字符串,并且返回出现的首地址,不过返回类型要用size_t

qq_37020000的博客 255

Codeforces Round #442 (Div. 2) A Alex and broken contest

A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Alex was creating a cont

Star77777的博客 731

Codeforces Round #442 (Div. 2) C - Slava and tanks

C. Slava and tanks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Slava plays his favorite game "Peace Lig

Star77777的博客 615

Codeforces Round #440 div2 A. Search for Pretty Integers

A. Search for Pretty Integers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two lists of non

Star77777的博客 544

Codeforces Round #441 div2 A. Trip For Meal

A. Trip For Mealtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputWinnie-the-Pooh likes honey very much! That is why he decided to visit his friends....

Star77777的博客 534

Codeforces Round #440 div2 C. Maximum splitting

C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given several queries. In the

Star77777的博客 488

Codeforces Round #441 div2 B. Divisiblity of Differences

B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output You are given a multiset of n

Star77777的博客 482
上一篇: Codeforces Round #442 (Div. 2) A Alex and broken contest
下一篇: Codeforces Round #442 (Div. 2) C - Slava and tanks
Star77777
博客等级 码龄10年 104粉丝 95原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值