当前位置:网站首页>[cf] 797 div3 D.Black and White Stripe
[cf] 797 div3 D.Black and White Stripe
2022-06-09 20:46:00 【*DDL_GzmBlog】
前言
题意 :
给定一个只含有 B W BW BW的字符串,询问最少修改多少次,使得至少有一段连续的 B B B至少是 K K K个
思路 :
我们设 W W W的贡献是 1 1 1,对字符串计算一次 前缀贡献,我们贪心的只取 K K K个连续的最小代价即可
code :
int sum[N];
int n,k;
void solve(){
cin>>n>>k;
string s;cin>>s;
s = " "+s;
for(int i=1;i<=n;i++)
sum[i] = sum[i-1]+(s[i]=='W'?1:0);
int res = INF;
for(int i=k;i<=n;i++)
res = min(res,sum[i] - sum[i-k]);
cout<<res<<endl;
}
int main(){
int t;cin>>t;while(t--)
solve();
return 0 ;
}
边栏推荐
- LeetCode 497. Random points in non overlapping rectangles**
- Examples of operator overloading in C #
- SSM driving school management system
- Vite Lerna Monorepo 项目改造初体验
- Go 调用 Kubernetes API 的 几个简单的 example
- Ceisum 3D scene demo
- Sequence traversal of binary tree
- 堆(优先队列)
- Analysis of source code data anti leakage solution
- C interface class learning
猜你喜欢

堆(优先队列)

Summary of linear regression

Parsing fluent from source code_ Precise local refresh of Redux

03 Wireshark TCP
![[operation and maintenance department] ad domain file permission management](/img/f4/5598384b352b2335145ffa58437439.png)
[operation and maintenance department] ad domain file permission management

逻辑回归总结

Numpy duplicate data

Force buckle 84- the largest rectangle in the histogram (monotone stack)

Ceisum 3D scene demo

Figure guessing game in C language
随机推荐
numpy中的ndarry排序
关于C#Unity读写文件
Le navigateur ne peut pas ouvrir Baidu, d'autres peuvent être ouverts normalement
CVPR2022 Oral | 用于实时地图视图语义分割的跨视图Transformer
[operation and maintenance department] ad domain file permission management
Share 10 tips on using reduce function
Examples of operator overloading in C #
二叉树的层序遍历
快速了解服务器IO的实现
The browser cannot open Baidu, and others can be opened normally
KubeVirt CICD Tekton (2) - task run:datavolume & ssh-key
Application of generic t in C #
Latex mathematical symbols Encyclopedia
排序-快速排序
Richter's replacement principle in C #
KubeVirt网络源码分析(3)- 虚拟机热迁移网络
Force buckle 84- the largest rectangle in the histogram (monotone stack)
GBase8s数据库select子句3
C language to realize computer automatic shutdown program -- it can be used to spoof roommate's computer
Can abstract classes inherit entity classes?