当前位置:网站首页>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;
}
边栏推荐
- Niuke challenge 53:c. strange magic array
- AGCO AI frontier promotion (6.26)
- Assert and constd13
- Leaflet load day map
- One article of the quantification framework backtrader read observer
- CVPR 2022文档图像分析与识别相关论文26篇汇集简介
- 【async/await】--异步编程最终解决方案
- Notes: the 11th and 12th generation mobile versions of Intel support the native thunderbolt4 interface, but the desktop version does not
- Educational Codeforces Round 117 (Rated for Div. 2)E. Messages
- Setup instance of layout manager login interface
猜你喜欢

From Celsius to the three arrows: encrypting the domino of the ten billion giants, and drying up the epic liquidity

布局管理器~登录界面的搭建实例

Relevant knowledge of information entropy

爱可可AI前沿推介(6.26)

Matlab programming related knowledge

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

MySQL主从复制与读写分离

7.consul service registration and discovery

AGCO AI frontier promotion (6.26)

Eigen(3):error: ‘Eigen’ has not been declared
随机推荐
Chinese output of PostGIS console is garbled
Sword finger offer 45.61 Sort (simple)
ThreadLocal巨坑!内存泄露只是小儿科...
Gartner 2022 Top Strategic Technology Trends Report
ArcGIS secondary development method - layer related operations (add, modify)
Win10 home vs pro vs enterprise vs enterprise LTSC
How to convert data in cell cell into data in matrix
Sword finger offer 18.22.25.52 Double pointer (simple)
虫子 类和对象 中
Flex & Bison 开始
Matplotlib common operations
Sword finger offer 10 Ⅰ 10Ⅱ. 63 dynamic planning (simple)
Eigen(3):error: ‘Eigen’ has not been declared
虫子 运算符重载的一个好玩的
windows版MySQL软件的安装与卸载
array
Sword finger offer 15.65.56 I 56Ⅱ. Bit operation (simple - medium)
Introduction to 26 papers related to CVPR 2022 document image analysis and recognition
SwiftUI找回丢失的列表视图(List)动画
登录认证服务