CodeForces 676C Vasya and String

C. Vasya and String (尺取法) C. Vasya and String 题目链接 大致题意: 给出一串只有a和b构成的字符串,字符串长度为n,可修改字符限制个数为k 求能得到的最长连续相同的字符串的长度 解题思路: 尺取法 维护区间内字符a的个数和字符b的个数 如果numa <= k || numb <= k,说明区间[l,r]可以修改为满足条件的情况,更新答案即可 AC代码: #include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i <= 阅读详情

High school student Vasya got a string of length n as a birthday present. This string consists of letters ‘a’ and ‘b’ only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.

Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?

Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.

The second line contains the string, consisting of letters ‘a’ and ‘b’ only.

Output
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.

Examples
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+7;
char s[N];
int n,k;
int check(char tmp)
{
    int l=0,r=0,cnt=0,ma=0;
    while(r<n)
    {
        if(s[r]!=tmp)cnt++;
        r++;
        while(cnt>k&&l<=r)
        {
             if(s[l]!=tmp)cnt--;
            l++;
        }
        while(r<n&&s[r]==tmp)
            r++;
        ma=max(r-l,ma);
    }
    return ma;
}
int main()
{
    scanf("%d%d%s",&n,&k,s);
    printf("%d\n",max(check('a'),check('b')));
}
【CodeForces 676】C - Vasya and String 啧啧啧,好不动脑的模拟。 好像wa 11.. 不管了。。 因为有更简单的做法。。 #include using namespace std; #define maxn 100010 char s[maxn]; int n,k; int tab[maxn],cnt; int dp[maxn]; int main(void) { scanf("%d%d",&n,&k);getchar(); 阅读详情

相关推荐

Springer期刊LaTeX模板中参考文献格式选择与编译错误的快速修复指南

本文针对Springer期刊LaTeX模板中参考文献编译后显示问号的常见问题,提供了快速修复指南。核心在于正确选择并配置与期刊匹配的参考文献格式文件(.bst),并执行标准的四步编译流程。文章详细解释了问题根源,并给出了从查找正确.bst文件到修改代码、执行编译的完整解决方案,帮助作者高效解决投稿中的技术障碍。

weixin_29266007的博客 410

Codeforces 676C Vasya and String (两点法)

Codeforces 676C Vasya and String (两点法)

Tc的专栏 1879

空间节省算法在Rowhammer防御中的应用与优化

空间节省算法(Space-Saving)是一种高效的流式数据处理算法,主要用于在有限内存条件下实时识别数据流中的高频项。其核心原理是通过维护固定大小的计数器表,动态跟踪最活跃的元素,适用于处理无限数据流场景。该算法在内存安全领域具有重要价值,特别是在Rowhammer攻击防御中,能够有效检测异常高频访问的DRAM行地址。通过结合计数器衰减策略(如DSAC)和混合架构设计,空间节省算法可以在保证低硬件开销的同时,提供高精度的攻击检测能力。这些技术已成功应用于现代DDR5内存控制器,展现出优异的工程实践价值。

weixin_31139479的博客 609

【题解】Vasya and String(贪心 + 尺取法)

八中OJ 洛谷 尺取法:顾名思义,像尺子一样取一段,借用挑战书上面的话说,尺取法通常是对数组保存一对下标,即所选取的区间的左右端点,然后根据实际情况不断地推进区间左右端点以得出答案。之所以需要掌握这个技巧,是因为尺取法比直接暴力枚举区间效率高很多,尤其是数据量大的时候,所以尺取法是一种高效的枚举区间的方法,一般用于求取有一定限制的区间个数或最短的区间等等。 贪心选择性质:算法中每一步选择都是...

cqbzlydd的博客 302

【论文详解】AlphaGenome——Sequence-to-Multimodal-Genome-Track

**AlphaGenome** 是由 **Google DeepMind** 于 2025 年 6 月发布的突破性 AI 模型,专门用于预测非编码区遗传变异的功能效应。该模型采用受 **U-Net** 启发的卷积架构结合 **Transformer** 模块,创新性地解决了传统模型在输入序列长度与预测分辨率之间的核心矛盾——能够在 **1M 碱基对的超长上下文** 下实现 **单核苷酸分辨率** 的精准预测。

zwhszdx的博客 970

空间数据分析的未来:AI与大数据的融合趋势

要理解“AI+大数据”的价值,首先需要明确空间数据的本质——它是带有地理位置信息的数据,核心特征是“空间相关性”(相邻的区域往往具有相似属性)。数据类型例子核心属性坐标数据GPS轨迹、手机基站定位数据纬度(latitude)、经度(longitude)几何数据OpenStreetMap的道路(线)、建筑(面)点、线、面的空间形状遥感数据卫星影像(Landsat)、无人机航拍图像素的空间坐标+光谱信息属性关联数据某区域的人口密度、房价、PM2.5值空间单元+非空间属性。

AI架构全栈开发实战笔记 1213

Vasya and String(尺取法)

High school student Vasya got a string of length n as a birthday present. This string consists of letters ‘a’ and ‘b’ only. Vasya denotes beauty of the string as the maximum length of a substring (con...

amazingee的博客 576

【Qt】解决 FTH: (11284): *** Fault tolerant heap shim applied to current process. (亲测有效)

计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers。容错堆垫片应用到当前的过程。这通常是由于以前的崩溃。win + r,输入regedit。

Fanjufei的博客 834

C. Vasya and String [思维]

C. Vasya and String 题意: 长为n,由a,b构成的串,可以做k次改变. 问最后最长的相等字串长度是多少. 思路:  k个肯定连续改的. 想了好久.......... #include&lt;bits/stdc++.h&gt; #define PI acos(-1.0) #define pb push_back #define F first #define S seco...

Haipai1998的博客 601

AMBA-CHI协议详解(三)

Write Transactions、Atomic transactions、 Stash transactions、 Dataless transactions的等各个事务的事务流。

Crazzy_M的博客 3191

基于CNN-LSTM融合模型的环卫车动态称重算法研究:从频率感知到精准质量估计

摘要: 针对环卫车辆动态称重需求,本研究提出一种基于CNN-LSTM融合网络的频率分析方法。通过在实验室构建振动频率采集系统,获取不同载重下的结构响应数据,经MATLAB进行信号处理和特征提取后,建立频率-质量的非线性映射模型。实验表明,该算法在静态和模拟动态场景下平均绝对误差小于1.5%,显著优于传统方法,为环卫车智能化管理提供了高精度实时称重方案。 关键词: 动态称重;深度学习;频率分析;CNN-LSTM;MATLAB。

AI的内部世界的博客 382

Codeforces 676C - Vasya and String 详解(二分前缀和+尺取两种写法)

C. Vasya and String time limit per test  1 second memory limit per test  256 megabytes input  standard input output  standard output High school student Vasya got a stri

K键盘里的青春K 1440

适航规章、标准,书籍资料下载汇总(增加DO-297 IMA)

从事IMA平台适航工作的朋友看过来,DO-297英文版PDF可以下载了!更新日志:2024-9-28:初版。2024-10-21:增加DO-330英文版PDF下载,后台回复关键词”330“获取下载链接。2024-10-30:增加DO-160G中文版(非机翻)和英文版PDF下载,后台回复关键词”160“获取下载链接。2024-11-10:增加DO-297英文版PDF下载,后台回复关键词”297“获取下载链接。以下是一些收集到的适航相关的资料,分享给大家。

qq_41854911的博客 1591

Codeforces 676 C. Vasya and String

题目链接:http://codeforces.com/contest/676/problem/C 题目大意:一个字符串只包含a和b,可以改变其中k个,求最大的美丽值,美丽值定义为子串中所含字符均相同的的最长子串的长度 题目分析:定义起点和终点,直接贪心。对于k次操作,要么全换a要么全换b,对这两种情况取最大即可,算的时候用两点法,r向右直到k用完,然后l从左开始加,不断还原k值(由于是

Seraphimon的博客 597

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

codeforces676C Vasya and String

Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output High school student Vasya got a string of l

nankeyimeng的博客 1100

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

codeforces 676C C. Vasya and String 尺取法

传送门:codeforces 676C C. Vasya and String(二分)题目大意问最多改变k个字母才能使相同字母组成的子串最长;解题思路因为题目中给定的只有a或者b字符,最长的方式无非就两种把a变为b,或者把b变为a。 //就那把b变为a举例子 我们想从左向右一直记录b的的个数,当b的个数大于能改变数的时候就记录下这个值,一这个点为终点,起始点为开始找到b,然后终点继续向右走这个过

woshinannan的专栏 493

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

codeforces676C. Vasya and String

C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output High school student Vasya got a string of length n

哇咔咔 753

【CodeForces 676C 】 Vasya and String 二分法

High school student Vasya got a string of length n as a birthday present. This string consists of letters ‘a’ and ‘b’ only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya

待到山花烂漫时 297

CodeForces - 676C C - Vasya and String

High school student Vasya got a string of length n as a birthday present. This string consists of letters ‘a’ and ‘b’ only. Vasya denotes beauty of the string as the maximum length of a substring (con...

Wolfgang 347

codeforces 676C Vasya and String

Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output High school student Vasya got a string of length n as a

SCAU_BIN的博客 945

Vasya and String CodeForces 676C 前缀和+二分

给出一串长度为n的字符串,字符串中只有‘a’或者'b',我们可以改变 k 次字母,我们可以得到的相同的连续子串最长有多长。

Sheepsheep 254

codeforces #354 div.2 C &&676C Vasya and String

题目链接:http://codeforces.com/problemset/problem/676/C——————————C. Vasya and String time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output High schoo

Tabris的博客 705

Codeforces 676C Vasya and String

题目链接:http://codeforces.com/problemset/problem/676/C 题意:给一个只含有ab的字符串,最多修改k个字符使得一段连续字符串只包含一种字符的长度最长。 思路:尺取法,记录当前连续区间字符串中a的个数,b的个数和当前区间左右边界。现在右边界不断右移加上一个字符,如果min(a,b)小于等于k(也就是说可以通过修改来达到这个区间全部为一

DS-K的博客 472

Vasya and String CodeForces - 676C(尺取法)

High school student Vasya got a string of length n as a birthday present. This string consists of letters ‘a’ and ‘b’ only. Vasya denotes beauty of the string as the maximum length of a substring (con...

starlet_kiss的博客 314

(尺取法)Codeforces 676C - Vasya and String

原题链接: http://codeforces.com/problemset/problem/676/C 题意: 有一串a和b组成的字符串,要求最多改k的字母的情况下,最长的相同子串。 例如k=2:abba->aaaa,k=3:aaabb->bbbbb 分析: 首先可以看出如果要最长的话,改的a或b一定是连续的k个a或b,因此只要计算连续的k个a或b...

dijieluan7764的博客 146

Codeforces 676C - Vasya and String 尺取法

题意:将长度为n的只包含a和b的字符串,中的字母替换k次,得到一个最长的只包含一种字母的字符串,输出最长的长度。 尺取法: 所谓尺取法,顾名思义,就是像一把尺子(固定某一条件),不断向右(左)移动,不断更新所求答案。一般用来求满足条件的最小区间。https://blog.csdn.net/weixin_41162823/article/details/80328404 分析:我们只要从左往右,...

samscream的博客 240
上一篇: zoj 3946 Highway Project
下一篇: hdu 1060 Leftmost Digit
oinei
博客等级 码龄10年 9粉丝 73原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值