当前位置: 代码迷 >> 综合 >> Codeforces Round 1384
  详细解决方案

Codeforces Round 1384

热度:34   发布时间:2024-02-01 12:39:09.0

A. Common Prefixes
题意:构造 n +1 个字符串,使得第 i 和 i+1 个字符串的公共前缀长度为 a[i].

题解:光理解题目就用了好久,想思路的时候想着一个个来,但前缀减小的情况没想清楚。看完官方题解豁然开朗。第一个串全部构造成’a’,然后前缀相等的部分我们不用管,只需要改变上一个字符串的第一个非前缀字符就行了,后面都不用管,然后直接输出。

#include <bits/stdc++.h>
using namespace std;
int t,n,u;
string s;
int main()
{int t;cin >> t;for (int i = 0; i < t; ++i){int n;cin >> n;s=string(200, 'a');cout << s << endl;for (int j = 0; j < n; ++j){int u;cin >> u;s[u] = s[u] == 'a' ? 'b' : 'a';cout << s << endl;}}return 0;
}
  相关解决方案