0
点赞
收藏
分享

微信扫一扫

A. Common Prefixes(构造思维) Codeforces Round #659 (Div. 2)

原题链接: ​​https://codeforces.com/contest/1384/problem/A​​

A. Common Prefixes(构造思维)   Codeforces Round #659 (Div. 2)_#define
测试样例

input
4
4
1 2 4 2
2
5 3
3
1 3 1
3
0 0 0
output
aeren
ari
arousal
around
ari
monogon
monogamy
monthly
kevinvu
kuroni
kurioni
korone
anton
loves
adhoc
problems

Note

Note
In the 1-st test case one of the possible answers is s=[aeren,ari,arousal,around,ari].
Lengths of longest common prefixes are:
Between aeren and ari →1
Between ari and arousal →2
Between arousal and around →4
Between around and ari →2

题意: 现在给定一个长度为A. Common Prefixes(构造思维)   Codeforces Round #659 (Div. 2)_#define_02的字符串前缀长度数组A. Common Prefixes(构造思维)   Codeforces Round #659 (Div. 2)_字符串_03A. Common Prefixes(构造思维)   Codeforces Round #659 (Div. 2)_#define_04表示着第A. Common Prefixes(构造思维)   Codeforces Round #659 (Div. 2)_ios_05个字符串与第A. Common Prefixes(构造思维)   Codeforces Round #659 (Div. 2)_#define_06个字符串的前缀长度,问你能否构造出这A. Common Prefixes(构造思维)   Codeforces Round #659 (Div. 2)_字符串_07个字符串使得满足这些条件?(题目保证一定有解。)

解题思路: 我们这样想,每一个字符串都与前面的有关除了第一个字符串,那么我们是不是可以去构造第一个字符串?因为只有它是未知的,至少它前面没有字符串,如果我们已知第一个字符串,我们根据A. Common Prefixes(构造思维)   Codeforces Round #659 (Div. 2)_#define_08只要修改前面那个字符串上第A. Common Prefixes(构造思维)   Codeforces Round #659 (Div. 2)_#define_09个字符串的值。 那么我们怎么构造则是解决这个题目的关键。我们要这样想:由于所有的元素都是字符,我们会想到用最简单的来表示,即用A. Common Prefixes(构造思维)   Codeforces Round #659 (Div. 2)_字符串_03A. Common Prefixes(构造思维)   Codeforces Round #659 (Div. 2)_ios_11这两个字母来表示差异,那么我们表示第一个字符串全表示为A. Common Prefixes(构造思维)   Codeforces Round #659 (Div. 2)_#define_12。之后的字符串皆可以根据前面字符串进行更改输出即可。OK,具体看代码。

AC代码

/*

*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int t,n;
int a[maxn];
char s[maxn];
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>t){
while(t--){
int maxx=0;
cin>>n;
rep(i,1,n){
cin>>a[i];
maxx=max(a[i],maxx);//找到最大的,构建这样的数组。
}
//接下来按顺序输出即可。
rep(i,0,maxx){
s[i]='a';
}
s[maxx+1]='\0';
cout<<s<<endl;
rep(i,1,n){
//即我们要对上个字符串所在位置进行更改。
if(s[a[i]]=='a')
s[a[i]]='b';
else
s[a[i]]='a';
cout<<s<<endl;
}
}
}
return 0;
}


举报

相关推荐

0 条评论