题目传送
题意:
给你一个n大小的数组,打印n+1个字符串,使得后一个字符串与前一个字符串的最长相同前缀长度对应于数组中的大小
思路:
贪心。
我们先构造出一个200长的字符串(因为题目中的限制就是200)
然后先打印出第一个字符串,第二个字符串则改动相应位置,使得最长前缀长度对应于数组中的值,然后依次下去
AC代码
#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 2e5 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int t;
cin >> t;
while(t--)
{
string s = "abcdefghijklmnopqrstuvwxyz",s1 = "";
int n;
cin >> n;
int arr[n+5] = {0};
for(int i = 1;i <= n;i++) cin >> arr[i];
for(int i = 0;i < 200;i++) s1 += s[i%26];
cout << s1 << endl;
for(int i = 1;i <= n;i++)
{
string a = s1;
a[arr[i]] != 'z' ? a[arr[i]] = 'z' : a[arr[i]] = 'a';
cout << a << endl;
s1 = a;
}
}
}