当前位置:网站首页>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;
}
边栏推荐
- Huiyuan, 30, is going to have a new owner
- MySQL 巨坑:update 更新慎用影响行数做判断!!!
- How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
- OSI 七层模型
- 如何将 DevSecOps 引入企业?
- Where is the operation of convertible bond renewal? Is it safer and more reliable to open an account
- 想问下大家伙,有无是从腾讯云MYSQL同步到其他地方的呀?腾讯云MySQL存到COS上的binlog
- Usage and usage instructions of JDBC connection pool
- I collect multiple Oracle tables at the same time. After collecting for a while, I will report that Oracle's OGA memory is exceeded. Have you encountered it?
- Object. defineProperty() - VS - new Proxy()
猜你喜欢

I spring and autumn blasting-1

百亿按摩仪蓝海,难出巨头

Good article inventory

I include of spring and Autumn

swiper. JS to achieve barrage effect

ionic cordova项目修改插件

Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
![P1451 calculate the number of cells / 1329: [example 8.2] cells](/img/c4/c62f3464608dbd6cf776c2cd7f07f3.png)
P1451 calculate the number of cells / 1329: [example 8.2] cells

Bugku telnet

Number protection AXB function! (essence)
随机推荐
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
1330: [example 8.3] minimum steps
[recruitment position] infrastructure software developer
How can the boss choose programmers to help me with development?
Install and configure Jenkins
爱可可AI前沿推介(7.5)
Detailed explanation of QT creator breakpoint debugger
你童年的快乐,都是被它承包了
ICML 2022 | explore the best architecture and training method of language model
Ctfshow web entry command execution
Magic methods and usage in PHP (PHP interview theory questions)
Appium自动化测试基础 — APPium基础操作API(二)
sql server学习笔记
Crud of MySQL
Bugku cyberpunk
Leetcode: Shortest Word Distance II
First PR notes
Calculate weight and comprehensive score by R entropy weight method
漫画:优秀的程序员具备哪些属性?
P1451 求细胞数量/1329:【例8.2】细胞