Codeforces Round #659 (Div. 2) A. Common Prefixes(思维)
The length of the longest common prefix of two strings and is defined as the maximum integer k0≤k≤min(n,m)) such that equals to
Koa the Koala initially has n+1 strings
For each i (1≤i≤n) she calculated — the length of the longest common prefix of and .
Several days later Koa found these numbers, but she couldn't remember the strings.
So Koa would like to find some strings which would have generated numbers . Can you help her?
If there are many answers print any. We can show that answer always exists for the given constraints.
Input
Output
Example
Input
Copy
4
4
1 2 4 2
2
5 3
3
1 3 1
3
0 0 0
Output
Copy
aeren
ari
arousal
around
ari
monogon
monogamy
monthly
kevinvu
kuroni
kurioni
korone
anton
loves
adhoc
problems
首先随便构造一个字符串作为第一个,然后对于每个,把上一个字符串下标为的字母换掉就得到当前字符串了(可以直接ASCII码减去'a'再加1,再对26取模)。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
string s = "";
for(int i = 0; i < 200; i++) s += 'a';
cout << s << endl;
for(int i = 1; i <= n; i++)
{
int temp;
cin >> temp;
s[temp] = (s[temp] - 'a' + 1) % 26 + 'a';
cout << s << endl;
}
}
return 0;
}
分类:
题库—Codeforces比赛
, 算法基础—思维题
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!