尺取法 C - Vasya and String CodeForces - 676C
#include<iostream>
using namespace std;
int main()
{
long long k,n;
cin>>n>>k;
string str;
cin>>str;
long long p=0,ans=0,s=0;
for(int i=0;i<n;++i)
{
if(str[i]=='b')
++p;
while(p>k)
{
if(str[s++]=='b') --p;
}
ans=max(ans,i-s+1);
}
p=0;
s=0;
for(int i=0;i<n;++i)
{
if(str[i]=='a')
++p;
while(p>k)
{
if(str[s++]=='a') --p;
}
ans=max(ans,i-s+1);
}
cout<<ans;
return 0;
}
尺取法详解:https://blog.csdn.net/lxt_lucia/article/details/81091597
尺取法 C - Vasya and String CodeForces - 676C的更多相关文章
- [CodeForces-1225B] TV Subscriptions 【贪心】【尺取法】
[CodeForces-1225B] TV Subscriptions [贪心][尺取法] 标签: 题解 codeforces题解 尺取法 题目描述 Time limit 2000 ms Memory ...
- Codeforces 676C Vasya and String(尺取法)
题目大概说给一个由a和b组成的字符串,最多能改变其中的k个字符,问通过改变能得到的最长连续且相同的字符串是多长. 用尺取法,改变成a和改变成b分别做一次:双指针i和j,j不停++,然后如果遇到需要改变 ...
- codeforces 676C C. Vasya and String(二分)
题目链接: C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Vasya and String(尺取法)
Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)
题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...
- 【CF676C】Vasya and String(二分查找,线性扫描尺取法)
题意: 给出一个长度为n的字符串,只有字符'a'和'b'.最多能改变k个字符,即把'a'变成'b'或把'b'变成'a'. 问改变后的最长连续相同字符的字串长度为多少. 首先是二分查找,好想也好写 .. ...
- Codeforces Round #354 (Div. 2)——C. Vasya and String(尺取)
C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)
题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...
- Codeforces Educational Codeforces Round 5 D. Longest k-Good Segment 尺取法
D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The arra ...
- CodeForces 701C They Are Everywhere 尺取法
简单的尺取法…… 先找到右边界 然后在已经有了所有字母后减小左边界…… 不断优化最短区间就好了~ #include<stdio.h> #include<string.h> #d ...
随机推荐
- TypeDB Forces 2023 (Div. 1 + Div. 2, Rated, Prizes!) A-E
比赛链接 A 题意 给一个正整数 \(n\) ,找到一组正整数 \(x,y \leq n\) ,满足 \(x^y \cdot y + y^x \cdot x = n\) . 题解 知识点:数学. 尝试 ...
- 行为型模式 - 备忘录模式Memento
学习而来,代码是自己敲的.也有些自己的理解在里边,有问题希望大家指出. 模式的定义与特点 在备忘录模式(Memento Pattern)下,为的是在不破坏封装性的前提下,捕获一个对象的内部状态,并在该 ...
- selenium注入js代码
from selenium import webdriver from selenium.webdriver import ActionChains import time dr = webdrive ...
- 【一句话】CAP原则
首先一句话: 如果出现网络分区(P),持有旧数据的节点是否要继续提供服务,提供就保证了可用(A),但数据不一定新,放弃了C:如果不提供服务,则意味着放弃了可用性A,但是保证数据一致(C). 我的理解: ...
- org.springframework.web.filter.CharacterEncodingFilter cannot be cast to javax.servlet.Filter异常
转:https://blog.csdn.net/u010670689/article/details/40301043 使用maven开发web应用程序, 启动的时候报错: jar not loade ...
- @mapper注解
1.标记这是一个映射接口,这样子写还是需要写xml文件 package com.atguigu.springcloud.dao; import com.atguigu.springcloud.enti ...
- Python实现类别变量的独热编码(One-hot Encoding)
本文介绍基于Python下OneHotEncoder与pd.get_dummies两种方法,实现机器学习中最优的编码方法--独热编码的方法. 目录 1 OneHotEncoder 2 pd.get ...
- STM32F4寄存器初始化系列:三重ADC——DMA
static void ADC_Init(void) { /********************DMA配置**************************/ DMA2_Stream0-> ...
- 一段简单的对TXT文件的操作代码
1 string txt = @"C:\DetectFolder\IPV4地址.txt"; 2 string path = ""; 3 4 if (File.E ...
- Docker自建仓库搭建记录
https://blog.csdn.net/u011943534/article/details/81331231 https://blog.csdn.net/u013165156/article/d ...