当前位置:网站首页>F. Min cost string problem solving Report
F. Min cost string problem solving Report
2022-07-05 15:25:00 【wch(】
F. Min Cost String Problem solving report
label : character string structure
subject

The question :
Give constant n,k, Let's use before k Lowercase letters are constructed with a length of n String
Letters can be in front k Any use or no use within the scope , But it is required to minimize the index pairs in the output string
When s[i]=s[j] And is s[i+1]=s[j+1] (1≤i<j<|s|) It constitutes an index pair
Their thinking :
To minimize index pairs , We can divide the string into one-to-one pairs ,
such as s=aaba At this time, we see three pairs aa ab ba It has been taken
Then the next idea is to list all Character pair Add to s in
If the string length is greater than or equal to n Before output n Characters
If the length of the character string is less than n
Because all the character pairs that can be formed are already in s It's in No matter what you add, there will be index pairs
We let s += s Until the length is greater than n Before interception n Character output
resize Function usage
When n The length is less than the string s The length of s.resize(n), Intercept s front n Characters
When n The length is greater than the string s The length of char a; s.resize(n,a), stay s Add characters after a until s Length up to n
Code implementation
#include <iostream>
#include <string>
using namespace std;
int main(){
long long n,k;
cin>>n>>k;
string s("");
for(int i=0;i<k;i++){
s+='a'+i;
for(int j=i+1;j<k;j++)
{
s+='a'+i;
s+='a'+j;
}
}
while(s.size()<n)s+=s;
s.resize(n);
cout<<s<<endl;
}
边栏推荐
- 1330: [example 8.3] minimum steps
- P6183 [USACO10MAR] The Rock Game S
- Photoshop plug-in - action related concepts - actions in non loaded execution action files - PS plug-in development
- CSRF, XSS science popularization and defense
- 数学建模之层次分析法(含MATLAB代码)
- OSI 七层模型
- lv_font_conv离线转换
- Select sort and bubble sort
- Reconnaissance des caractères easycr
- R 熵权法计算权重及综合得分
猜你喜欢
![P6183 [USACO10MAR] The Rock Game S](/img/f4/d8c8763c27385d759d117b515fbf0f.png)
P6183 [USACO10MAR] The Rock Game S

Bugku's steganography

Common PHP interview questions (1) (written PHP interview questions)

Machine learning notes - gray wolf optimization

Creation and optimization of MySQL index

Detailed explanation of QT creator breakpoint debugger

Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking

DVWA range clearance tutorial

Bugku telnet

Bubble sort, insert sort
随机推荐
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
Dark horse programmer - software testing -10 stage 2-linux and database -44-57 why learn database, description of database classification relational database, description of Navicat operation data, de
百亿按摩仪蓝海,难出巨头
[12 classic written questions of array and advanced pointer] these questions meet all your illusions about array and pointer, come on!
Crud of MySQL
Can I pass the PMP Exam in 20 days?
MySQL 巨坑:update 更新慎用影响行数做判断!!!
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
漫画:程序员不是修电脑的!
Anaconda uses China University of science and technology source
Reasons and solutions for redis cache penetration and cache avalanche
Creation and optimization of MySQL index
Bugku cyberpunk
Bugku's eyes are not real
Hongmeng system -- Analysis from the perspective of business
Usage and usage instructions of JDBC connection pool
Au - delà du PARM! La maîtrise de l'Université de Pékin propose diverse pour actualiser complètement le classement du raisonnement du NLP
GPS原始坐标转百度地图坐标(纯C代码)
P6183 [USACO10MAR] The Rock Game S
Huawei Hubble incarnation hard technology IPO harvester