zoukankan      html  css  js  c++  java
  • Codeforces C

    C - String Reconstruction

    方法一:把确定的点的父亲节点设为下一个点,这样访问过的点的根节点都是没访问过的点。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e6+5;
    char s[N],res[N*2];
    int fa[N*2];
    int Find(int x)
    {
        return x==fa[x]?x:fa[x]=Find(fa[x]);
    }
    int main()
    {
        for(int i=0;i<N*2;i++)fa[i]=i;
        int n,t,x;
        scanf("%d",&n);
        int ml=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s",s);
            scanf("%d",&t);
            int l=strlen(s);
            while(t--)
            {
                scanf("%d",&x);
                ml=max(ml,l+x-1);
                int y=x;
                while((y=Find(y))<=l+x-1)
                {
                    res[y]=s[y-x];
                    fa[y]=y+1;
                }
            }
        }
        for(int i=1;i<=ml;i++)if(!res[i])res[i]='a';
        puts(res+1);
        return 0;
    }

    方法二:把所有点放进set容器里,拜访过的点就删掉。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e6+5;
    char s[N],res[N*2];
    set<int>ss;
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        for(int i=1;i<N*2;i++)ss.insert(i);
        int n,t,a;
        cin>>n;
        int ml=0;
        for(int i=0;i<n;i++)
        {
            cin>>s;
            cin>>t;
            int l=strlen(s);
            while(t--)
            {
                cin>>a;
                while(1)
                {
                    set<int>::iterator it=ss.lower_bound(a);
                    if(it==ss.end()||*it-a>=l)break;
                    ml=max(ml,*it);
                    res[*it]=s[*it-a];
                    ss.erase(it);
                }
            }
        }
        for(int i=1;i<ml+1;i++)if(!res[i])res[i]='a';
        puts(res+1);
        return 0;
    }
  • 相关阅读:
    html语法
    mysql常见的使用语法
    文件相关命令
    linux文件管理
    mysql常见名词解释
    MySQL初识
    文件管理
    并发基础知识3
    Bash shell初识
    【Spring Boot】ActiveMQ 发布/订阅消息模式介绍
  • 原文地址:https://www.cnblogs.com/widsom/p/7156266.html
Copyright © 2011-2022 走看看