当前位置:网站首页>cf:D. Black and White Stripe【连续k个中最少的个数 + 滑动窗口】
cf:D. Black and White Stripe【连续k个中最少的个数 + 滑动窗口】
2022-06-11 18:37:00 【白速龙王的回眸】

分析
每次l和r前进一个
分析头和尾的元素,来得到当前窗口中最少的个数即可
Ac code
for t in range(int(input())):
#print(str(t) + ':')
n, k = list(map(int, input().split()))
s = input()
cntW = 0
ans = 0xffffffff
for i in range(k):
if s[i] == 'W':
cntW += 1
ans = min(ans, cntW)
for i in range(k, n):
if s[i] == 'W' and s[i - k] == 'W':
pass
elif s[i] == 'W' and s[i - k] == 'B':
cntW += 1
elif s[i] == 'B' and s[i - k] == 'W':
cntW -= 1
elif s[i] == 'B' and s[i - k] == 'B':
pass
ans = min(ans, cntW)
print(ans)
总结
思维转换 + 滑动窗口
边栏推荐
- Common operations of Visio
- 力扣39题组合总和
- Mysql深入完全学习---阶段1---学习总述
- [c language] shift elements after sorting elements of an array
- *Use of jetpack notes room
- Analysis of runtime instantiation of XML view root node in SAP ui5
- 【题解】Codeforces Round #798 (Div. 2)
- Force deduction 32 questions longest valid bracket
- Force buckle 34 finds the first and last positions of elements in a sorted array
- Uni app Muke hot search project (I) production of tabbar
猜你喜欢

Introduction to basic use and pit closure of BigDecimal

Common interview questions of network and concurrent programming

On the problem that the while loop condition in keil does not hold but cannot jump out

北京邮电大学2023级工商管理硕士MBA(非全日制)已开启

*Jetpack notes understanding of lifecycle ViewModel and livedata

力扣刷题——二叉树的层序遍历Ⅱ

JS实现全屏展示的具体方法

The nearest common ancestor of binary tree
Function development of user information management

map和set
随机推荐
求数据库设计毕业信息管理
TI AM64x——最新16nm处理平台,专为工业网关、工业机器人而生
Add your favorite background music
Surveillance des fonctions de perte avec visdom
Project management of workflow and business service on SAP BTP
力扣23题,合并K个升序链表
力扣33题,搜索旋转排序数组
Quanzhi technology T3 development board (4-core arm cortex-a7) - mqtt communication protocol case
Niu Ke's question -- finding the least common multiple
v-for循环遍历
手把手教你学会FIRST集和FOLLOW集!!!!吐血收藏!!保姆级讲解!!!
* Jetpack 笔记 使用DataBinding
Function development of user information management
力扣刷题——二叉树的层序遍历
Téléchargement et téléchargement des fichiers nécessaires au développement
Common interview questions of network and concurrent programming
Some problems of DC-DC bootstrap capacitor
牛客刷题——不要二
The HashSet collection stores student objects and traverses
Force deduction 23 questions, merging K ascending linked lists