C - String Reconstruction

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

代码:

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

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

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+;
char s[N],res[N*];
set<int>ss;
int main()
{
ios::sync_with_stdio(false);
cin.tie();
for(int i=;i<N*;i++)ss.insert(i);
int n,t,a;
cin>>n;
int ml=;
for(int i=;i<n;i++)
{
cin>>s;
cin>>t;
int l=strlen(s);
while(t--)
{
cin>>a;
while()
{
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=;i<ml+;i++)if(!res[i])res[i]='a';
puts(res+);
return ;
}

Codeforces C - String Reconstruction的更多相关文章

  1. Codeforces - 828C String Reconstruction —— 并查集find()函数

    题目链接:http://codeforces.com/contest/828/problem/C C. String Reconstruction time limit per test 2 seco ...

  2. CodeForces - 828C String Reconstruction 并查集(next跳)

    String Reconstruction Ivan had string s consisting of small English letters. However, his friend Jul ...

  3. CodeForces 828C String Reconstruction(并查集思想)

    题意:给你n个串,给你每个串在总串中开始的每个位置,问你最小字典序总串. 思路:显然这道题有很多重复填涂的地方,那么这里的时间花费就会特别高. 我们维护一个并查集fa,用fa[i]记录从第i位置开始第 ...

  4. Codeforces 828C String Reconstruction【并查集巧妙运用】

    LINK 题目大意 给你n个串和在原串中的出现位置,问原串 思路 直接跑肯定是GG 考虑怎么优化 因为保证有解,所以考虑过的点我们就不再考虑 用并查集维护当前每个点之后最早的没有被更新过的点 然后就做 ...

  5. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction 并查集

    C. String Reconstruction 题目连接: http://codeforces.com/contest/828/problem/C Description Ivan had stri ...

  6. Educational Codeforces Round 94 (Rated for Div. 2) String Similarity、RPG Protagonist、Binary String Reconstruction、Zigzags 思维

    题目链接:String Similarity 题意: 首先题目定义了两个串的相似(串的构成是0.1),如果两个串存在对于一个下标k,它们的值一样,那么这两个串就相似 然后题目给你一个长度为2n-1的串 ...

  7. Codeforces828 C. String Reconstruction

    C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. CF1400-C. Binary String Reconstruction

    CF1400-C. Binary String Reconstruction 题意: 对于一个二进制字符串\(s\),以及一个给定的\(x\),你可以通过一下操作来得到字符串\(w\): 对于字符串\ ...

  9. [CodeForces]String Reconstruction

    http://codeforces.com/contest/828/problem/C 并查集的神奇应用. #include<bits/stdc++.h> using namespace ...

随机推荐

  1. js随机点名系统

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 【Java】系统漏洞:关于用户登录后操作的注意事项

    项目背景: SpringMVC + Mybatis  + MySql数据库(javaWeb项目开发) 相关模块:登录,个人详细信息修改,订单详情查询 相关漏洞介绍: 1.登录的验证码:登录的验证码一定 ...

  3. 新浪微博 SAE

    一.云平台中云是指互联网,网络的一种比喻说法,顾名思义,这种平台允许开发者们或是将写好的程序放在“云”里运行,或是使用“云”里提供的服务,或二者皆是. 二.开发类云平台比较: 1.鼻祖 GOOGLE ...

  4. JSTL—标签

    什么是JSTL标签? Jsp标准标签库(JSP Standerd Tag Library) JSTL的优点是什么? 1) 提供一组标准的标签 2)可用于编写动态功能 使用JSTL的步骤? 1)引入ja ...

  5. pandas练习(三)------ 数据分组

    探索酒类消费数据 相关数据见(github) 步骤1 - 导入pandas库 import pandas as pd 步骤2 - 数据集 path3 = "./data/drinks.csv ...

  6. python 元组 序列上使用enumerate()函数

    不能直接for n,x,y in enumerate(data)

  7. linux常用命令:tar 命令

    通过SSH访问服务器,难免会要用到压缩,解压缩,打包,解包等,这时候tar命令就是是必不可少的一个功能强大的工具.linux中最流行的tar是麻雀虽小,五脏俱全,功能强大. tar 命令可以为linu ...

  8. Win10安装MySQL5.7.22 解压缩版(手动配置)方法

    1.下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads 直接点击下载项 下载后: 2.可以把解压的内容随便放到一个目录,我的是如 ...

  9. Linux服务器---apache配置文件

    Apache配置文件 Apache的配置文件默认路径是“/etc/httpd/conf/httpd.conf”,编辑该文件就可以修改Apache的配置 1.设置网页主目录,参数DocumentRoot ...

  10. zendstudio中加入对tpl文件的支持,用HTML Editor编辑器编辑

    zendstudio中加入对tpl文件的支持,用HTML Editor编辑器编辑:ThinkPHP中默认使用的tpl在zendstudio中默认打开都是文本编辑器的,没有语法提示开发效率很低,直接设置 ...