CF 828C String Reconstruction(暴力)

2 篇文章 0 订阅
1 篇文章 0 订阅
  • 题目大意
    给你一个字符串中的一些信息:某些字串和这些字串的位置,同一个字串可以出现很多次,输出原字符串
  • 分析
    我的做法是用 f[i] 记录以 i <script type="math/tex" id="MathJax-Element-2">i</script>开头的最长的子串,这样只需要线性扫一遍就行了

  • 代码

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
#define LL long long int
const int MAXN=3000505;
int n;
int max_len;
string s[MAXN];
int f[MAXN];//f[]为0表示没有被覆盖
char ans[MAXN];
void In()
{
    int k;
    int a;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        scanf("%d",&k);
        for(int j=1;j<=k;j++)
        {
            scanf("%d",&a);
            if(s[i].size()>=s[f[a]].size()) f[a]=i;
            if(a+s[i].size()-1 > max_len)max_len=a+s[i].size()-1;
        }
    }
}
void Work()
{
    int cur=1;
    int i=0;
    int j=0;
    int temp_max=0;
    while(cur<=max_len)
    {
        if(cur<=temp_max)
        {
            if(f[cur]!=0 && cur+s[f[cur]].size()-1 > temp_max)
            {
                temp_max=cur+s[f[cur]].size()-1;
                i=f[cur];
                j=0;
            }
            ans[cur++]=s[i][j++];
        }
        else if(f[cur]==0)ans[cur++]='a';
        else
        {
            temp_max=cur+s[f[cur]].size()-1;
            i=f[cur];
            j=0;
            ans[cur++]=s[i][j++];
        }
    }
}
int main()
{
    In();
    Work();
    for(int i=1;i<=max_len;i++)cout<<ans[i];
    cout<<endl;
    return 0;
}
/*

*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值