题目链接:https://cn.vjudge.net/contest/325616#problem/D
Input
3
a 4 1 3 5 7
ab 2 1 5
ca 1 4
Output
abacaba
翻译:
构造出来一个最小字典序的字符串,使得其满足n个条件。这n个条件中每个条件有一个连续的子字符串。然后有Ki个位子,表示这些字符串出现的位子。保证有解,n个条件互相没有矛盾
分析:
对于赋过值的位置,因为n个条件没有矛盾,所以直接跳过去。例如,字符串a的四个位置,对于字符串ab的1位置,可以直接跳过去。对于每一个位置,用t记录所能到达的最大位置,和下一个起始位置比较。
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 2000001
char a[N],b[N];
int main()
{
int T;
while(~scanf("%d",&T))
{
int mx=-1;
memset(a,-1,sizeof(a));
while(T--)
{
int t=-1;
scanf("%s",b);
int len=strlen(b);
int num;/*num个位置*/
scanf("%d",&num);
while(num--)
{
int location;
scanf("%d",&location);
mx=max(mx,location+len-1);//找到最大的位置
for(int i=max(t,location-1); i<location+len-1; i++)
a[i]=b[i-location+1];
t=location+len-1;
}
}
for(int i=0; i<mx; i++)
{
if(a[i]==-1)
printf("a");
else
printf("%c",a[i]);
}
printf("\n");
}
return 0;
}