CodeForces - 827A String Reconstruction(赋过值的位置如何跳过去的问题)

题目链接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;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zaiyang遇见

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值