String Reconstruction (并查集)
并查集维护和我这个位置的字母连续的已经被填充的字母能到达的最右边的第一个还没有填充的位置,然后把这个位置填上应该填的东西,然后把这个位置和下一个位置连接起来,如果下一个位置还没有填,我就会把下一个位置填上,如果填过了,就会跳到后面的还没有填的地方
#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lowbit(x) (x & (-x))
#define INOPEM freopen("in.txt", "r", stdin)
#define OUTOPEN freopen("out.txt", "w", stdout) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 2e6+;
const int maxm = ;
const int mod = 1e9+;
using namespace std; int n, m;
int T, tol;
char tmp[maxn];
char s[maxn];
int fa[maxn]; int find(int x) {
return fa[x] == x ? x : fa[x] = find(fa[x]);
} void bind(int u, int v) {
int x = find(u);
int y = find(v);
if(x == y) return ;
if(x < y) fa[x] = y;
else fa[y] = x;
return ;
} int main() {
memset(s, , sizeof s);
for(int i=; i<maxn; i++) fa[i] = i;
scanf("%d", &m);
n = ;
int q;
while(m--) {
scanf("%s", tmp);
int len = strlen(tmp);
scanf("%d", &q);
while(q--) {
int pos;
scanf("%d", &pos);
n = max(n, pos+len-);
for(int i=find(pos); i<pos+len; i=find(i+)) {
s[i] = tmp[i-pos];
bind(i, i+);
}
}
}
for(int i=; i<=n; i++) printf("%c", s[i] ? s[i] : 'a');
printf("\n");
return ;
}
String Reconstruction (并查集)的更多相关文章
- 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 ...
- Codeforces - 828C String Reconstruction —— 并查集find()函数
题目链接:http://codeforces.com/contest/828/problem/C C. String Reconstruction time limit per test 2 seco ...
- CodeForces - 828C String Reconstruction 并查集(next跳)
String Reconstruction Ivan had string s consisting of small English letters. However, his friend Jul ...
- Aizu - 2564 Tree Reconstruction 并查集
Aizu - 2564 Tree Reconstruction 题意:一个有向图,要使得能确定每一条边的权值,要求是每个点的入权和出权相等,问你最少需要确定多少条边 思路:这题好像有一个定理之类的,对 ...
- 算法初级面试题05——哈希函数/表、生成多个哈希函数、哈希扩容、利用哈希分流找出大文件的重复内容、设计RandomPool结构、布隆过滤器、一致性哈希、并查集、岛问题
今天主要讨论:哈希函数.哈希表.布隆过滤器.一致性哈希.并查集的介绍和应用. 题目一 认识哈希函数和哈希表 1.输入无限大 2.输出有限的S集合 3.输入什么就输出什么 4.会发生哈希碰撞 5.会均匀 ...
- CodeForces 828C String Reconstruction(并查集思想)
题意:给你n个串,给你每个串在总串中开始的每个位置,问你最小字典序总串. 思路:显然这道题有很多重复填涂的地方,那么这里的时间花费就会特别高. 我们维护一个并查集fa,用fa[i]记录从第i位置开始第 ...
- CodeForces - 827A:String Reconstruction (基础并查集)
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
- 【数轴涂色+并查集路径压缩+加速】C. String Reconstruction
http://codeforces.com/contest/828/problem/C [题意] [思路] 因为题目保证一定有解,所有优化时间复杂度的关键就是不要重复染色,所以我们可以用并查集维护区间 ...
- Codeforces 828C String Reconstruction【并查集巧妙运用】
LINK 题目大意 给你n个串和在原串中的出现位置,问原串 思路 直接跑肯定是GG 考虑怎么优化 因为保证有解,所以考虑过的点我们就不再考虑 用并查集维护当前每个点之后最早的没有被更新过的点 然后就做 ...
随机推荐
- MySQL使用select查询时,在查询结果中增加一个字段并指定固定值
假设需求是这样的: mysql> desc user; +-------+----------+------+-----+---------+----------------+ | Field ...
- 爬虫——cookies池的搭建
https://github.com/Python3WebSpider/cookiesPool
- 文件传输协议FTP、SFTP和SCP
网络通信协议分层 应用层: HTTP(Hypertext Transfer Protocol 超文本传输协议,显示网页) DNS(Domain Name System) FTP(File Transf ...
- React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton)
React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton) 一,需求与简单介绍 在开发项目时发现RN没有给提供RadioButton和Rad ...
- asp.net core下一个简单的分页技术
在做web应用的时候免不了要对数据进行分页,我最近在做asp.net core的开发的时候就遇到了这个需求,现在简单的记录一下: public class PaginatedList<T> ...
- asp.net core发布到linux
在发布到linux的过程中出现两个问题现在总结一下: 我的虚拟机是安装到本机上面的,所以,应该在虚拟机的设置里面设置端口映射.具体设置如下: 选择vm上方的编辑 在弹出的框中选择VMnet8,点击下方 ...
- MySQL 日期类型函数及使用
1 MySQL 数据库中有五种与日期时间有关的数据类型,各种日期数据类型所占空间如下图所示: 2 datetime 与 date datetime 占用8字节,是占用空间最多的一种日期格式.它显示日期 ...
- Docker 给 故障停掉的 container 增加 restart 参数
操作过程见图: 执行的命令比较简单: docker container update --restart=always containername 即可.
- Mybatis Dao层注解及XML组合Dao的开发方式
mybatis可以用xml进行数据操作,也可以在dao层用注解的方式,也可以采取xml和dao层接口组合使用的方法.显然 ,后者更加简单. 实体类Student package com.zhao. ...
- MySQL 字段内容区分大小写
数据由Oracle 迁入MySQL ,由于之前Oracle区分大小写,MySQL的配置使用了默认配置,导致一些数据导入失败,有的唯一键报错,冲突. 将测试过程记录在下面. 数据库版本:MySQL 5. ...