当前位置:网站首页>D - Face Produces Unhappiness
D - Face Produces Unhappiness
2022-06-26 14:23:00 【Honestbutter-】
D - Face Produces Unhappiness
The question :
- If there is
s[i-1]=s[i],happy The number of people +1 - What we can do is , Select an interval to reverse the whole character (
LchangeR) - At most
koperations ( Note that not necessarily K operations )
Ideas :
- We first record the original string
happyThe number of people ( as long ass[i-1]==s[i], namelyLLType orRRtype , Because we only discuss the properties of adjacent two at a time ) - Then the rest is in the string , only
LRThe type andRLtype
eg:LRLRLperhapsRLRL( At least three characters or more are such LRL or RLR type ), We will find that whether it is flipping L perhaps R, Can get three consecutive equal characters , bringhappyThe number of +2 - So we added
happyThe number is2*k, however ! The most in a string happy The number of people isn-1personal , What is givenkFor the most operations , It may be much larger than the maximum operation we can actually carry out !
So we need to takehappy=min(happy+2*k,n-1);
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
string s;
cin>>s;
int happy=0;
for(int i=1;i<n;i++)
if(s[i]==s[i-1]) happy++;
cout<<min(happy+2*k,n-1)<<endl;
return 0;
}
边栏推荐
- How to personalize VIM editor format (DIY)
- 9 regulations and 6 prohibitions! The Ministry of education and the emergency management department jointly issued the nine provisions on fire safety management of off campus training institutions
- Server create virtual environment run code
- Sword finger offer 09.30 Stack
- Mathematical design D12 according to string function
- How to call self written functions in MATLAB
- A must for programmers, an artifact utools that can improve your work efficiency n times
- 方程推导:二阶有源带通滤波器设计!(下载:教程+原理图+视频+代码)
- Free machine learning dataset website (6300+ dataset)
- CVPR 2022文档图像分析与识别相关论文26篇汇集简介
猜你喜欢

Sword finger offer 10 Ⅰ 10Ⅱ. 63 dynamic planning (simple)

Hard (magnetic) disk (I)

vmware部分设置

Gartner 2022 Top Strategic Technology Trends Report

Hard (magnetic) disk (II)

Self created notes (unique in the whole network, continuously updated)

Sword finger offer 15.65.56 I 56Ⅱ. Bit operation (simple - medium)

Gartner 2022年顶级战略技术趋势报告

爱可可AI前沿推介(6.26)

布局管理器~登录界面的搭建实例
随机推荐
2021-10-29 atcoder ABC157——B - Bingo
Gartner 2022年顶级战略技术趋势报告
C language | the difference between heap and stack
Knowledge about the determination coefficient R2 and the relationship with the correlation coefficient
虫子 类和对象 上
8. Ribbon load balancing service call
In insect classes and objects
Sword finger offer 15.65.56 I 56Ⅱ. Bit operation (simple - medium)
Notes: the 11th and 12th generation mobile versions of Intel support the native thunderbolt4 interface, but the desktop version does not
hands-on-data-analysis 第三单元 模型搭建和评估
Flex & Bison 开始
VIM auto fill auto indent explanation
方程推导:二阶有源带通滤波器设计!(下载:教程+原理图+视频+代码)
Half search, character array definition, character array uses D11
Use performance to see what the browser is doing
transformers DataCollatorWithPadding类
[scoi2016] lucky numbers
array
Correlation analysis related knowledge
[sdoi2013] forest