码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces C - String Reconstruction

时间:2017-07-12 16:50:15      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:方法   get   const   bsp   ace   容器   i++   --   problem   

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;
}

 

Codeforces C - String Reconstruction

标签:方法   get   const   bsp   ace   容器   i++   --   problem   

原文地址:http://www.cnblogs.com/widsom/p/7156266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!