当前位置:网站首页>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;
}
边栏推荐
- Creation and use of thymeleaf template
- Database learning - Database Security
- Your childhood happiness was contracted by it
- 市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
- 数据库学习——数据库安全性
- Can I pass the PMP Exam in 20 days?
- P6183 [USACO10MAR] The Rock Game S
- No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle
- "Sequelae" of the withdrawal of community group purchase from the city
- MySQL之CRUD
猜你喜欢

Your childhood happiness was contracted by it

MySQL之CRUD

计算中间件 Apache Linkis参数解读

Select sort and bubble sort
![1330: [example 8.3] minimum steps](/img/69/9cb13ac4f47979b498fa2254894ed1.gif)
1330: [example 8.3] minimum steps

Crud de MySQL

可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成

Reasons and solutions for redis cache penetration and cache avalanche

超越PaLM!北大碩士提出DiVeRSe,全面刷新NLP推理排行榜

Coding devsecops helps financial enterprises run out of digital acceleration
随机推荐
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
I spring and autumn blasting-2
Common interview questions about swoole
Can gbase 8A view the location of SQL statement history?
Leetcode: Shortest Word Distance II
lvgl 显示图片示例
Optional parameters in the for loop
B站做短视频,学抖音死,学YouTube生?
Bugku's steganography
queryRunner. Query method
Anti shake and throttling
P1451 calculate the number of cells / 1329: [example 8.2] cells
30岁汇源,要换新主人了
easyOCR 字符識別
maxcompute有没有能查询 表当前存储容量的大小(kb) 的sql?
MySQL 巨坑:update 更新慎用影响行数做判断!!!
Redis distributed lock principle and its implementation with PHP (1)
做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
OSI 七层模型
CODING DevSecOps 助力金融企业跑出数字加速度