当前位置:网站首页>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;
}
边栏推荐
- 我这边同时采集多个oracle表,采集一会以后,会报oracle的oga内存超出,大家有没有遇到的?
- Fr exercise topic --- comprehensive question
- Can I pass the PMP Exam in 20 days?
- Creation and use of thymeleaf template
- Object. defineProperty() - VS - new Proxy()
- Misc Basic test method and knowledge points of CTF
- [recruitment position] infrastructure software developer
- Common redis data types and application scenarios
- 如何将 DevSecOps 引入企业?
- sql server char nchar varchar和nvarchar的区别
猜你喜欢
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
OSI 七层模型
Photoshop plug-in action related concepts actionlist actiondescriptor actionlist action execution load call delete PS plug-in development
美团优选管理层变动:老将刘薇调岗,前阿里高管加盟
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
Crud de MySQL
30岁汇源,要换新主人了
华为哈勃化身硬科技IPO收割机
Bugku alert
12 MySQL interview questions that you must chew through to enter Alibaba
随机推荐
JS topic - console log()
Bugku easy_ nbt
MySQL 巨坑:update 更新慎用影响行数做判断!!!
漫画:优秀的程序员具备哪些属性?
MySQL----函数
30岁汇源,要换新主人了
"Sequelae" of the withdrawal of community group purchase from the city
Ionic Cordova project modification plug-in
I include of spring and Autumn
What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
Hongmeng system -- Analysis from the perspective of business
ionic cordova项目修改插件
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
机器学习笔记 - 灰狼优化
Redis distributed lock principle and its implementation with PHP (1)
Aike AI frontier promotion (7.5)
[recruitment position] Software Engineer (full stack) - public safety direction
mapper.xml文件中的注释
PHP high concurrency and large traffic solution (PHP interview theory question)
Calculate weight and comprehensive score by R entropy weight method