LINK


题目大意

给你n个串和在原串中的出现位置,问原串


思路

直接跑肯定是GG

考虑怎么优化

因为保证有解,所以考虑过的点我们就不再考虑

用并查集维护当前每个点之后最早的没有被更新过的点

然后就做完了,很巧妙对吧


c++//Author: dream_maker
#include<bits/stdc++.h>
using namespace std;
//----------------------------------------------
//typename
typedef long long ll;
//convenient for
#define fu(a, b, c) for (int a = b; a <= c; ++a)
#define fd(a, b, c) for (int a = b; a >= c; --a)
#define fv(a, b) for (int a = 0; a < (signed)b.size(); ++a)
//inf of different typename
const int INF_of_int = 1e9;
const ll INF_of_ll = 1e18;
//fast read and write
template <typename T>
void Read(T &x) {
bool w = 1;x = 0;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') w = 0, c = getchar();
while (isdigit(c)) {
x = (x<<1) + (x<<3) + c -'0';
c = getchar();
}
if (!w) x = -x;
}
template <typename T>
void Write(T x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) Write(x / 10);
putchar(x % 10 + '0');
}
//----------------------------------------------
const int N = 1e6 + 10;
int n, fa[N << 1];
char s[N << 1], c[N];
void init() {
fu(i, 1, (N << 1) - 1) fa[i] = i;
}
int find(int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
int main() {
Read(n);
init();
int maxl = 0;
fu(i, 1, n) {
scanf("%s", c + 1);
int num, len = strlen(c + 1), pos;
Read(num);
fu(j, 1, num) {
Read(pos);
maxl = max(maxl, pos + len - 1);
for (int k = find(pos); k <= pos + len - 1; k = find(k)){
s[k] = c[k - pos + 1];
fa[k] = k + 1;
}
}
}
fu(i, 1, maxl) if (!s[i]) s[i] = 'a';
printf("%s", s + 1);
return 0;
}

Codeforces 828C 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 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 ...

  5. Codeforces Gym 100463E Spies 并查集

    Spies Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Desc ...

  6. Codeforces 650C Table Compression (并查集)

    题意:M×N的矩阵 让你保持每行每列的大小对应关系不变,将矩阵重写,重写后的最大值最小. 思路:离散化思想+并查集,详见代码 好题! #include <iostream> #includ ...

  7. Codeforces 468B Two Sets 并查集

    题目大意:给出n个数,要求将n个数分配到两个集合中,集合0中的元素x,要求A-x也再0中,同理1集合. 写了几个版本号,一直WA在第8组数据...最后參考下ans,写了并查集过了 学到:1.注意离散的 ...

  8. Codeforces 859E Desk Disorder 并查集找环,乘法原理

    题目链接:http://codeforces.com/contest/859/problem/E 题意:有N个人.2N个座位.现在告诉你这N个人它们现在的座位.以及它们想去的座位.每个人可以去它们想去 ...

  9. CodeForces 566D Restructuring Company (并查集+链表)

    题意:给定 3 种操作, 第一种 1 u v 把 u 和 v 合并 第二种 2 l r 把 l - r 这一段区间合并 第三种 3 u v 判断 u 和 v 是不是在同一集合中. 析:很容易知道是用并 ...

随机推荐

  1. 谈一谈URL

    作者:ManfredHu 链接:http://www.manfredhu.com/2017/08/16/22-url/index.html 声明:版权所有,转载请保留本段信息,谢谢大家 URL URL ...

  2. css hover dropdown

    html-------------------------- <div class="dropdown"> <span>鼠标移动到我这!</span& ...

  3. SOA和SaaS的区别

    SOA,Service Oriented ArchITecture,面向服务的架构 SaaS,Software as a Service https://blog.csdn.net/chenyi888 ...

  4. java 位数补0处理(转)

    数据库中表的ID为4位数字,如:0001,0012,0123,1234 如果插入的值不满足4位,需要进行转换,有两种方法 第一种方法以: int n = 1;         NumberFormat ...

  5. Object.assign() 从一个或多个源对象复制到目标对象

    Object.assign()方法用于将所有可枚举属性的值从一个或多个源对象复制到目标对象.它将返回目标对象. 1.语法: Object.assign(target, ... , sources) 参 ...

  6. 运行UART的程序

    1 捎程序的时候,注意,捎入的是norflash,此时的按钮应该在norFlash.2 当捎入成功的时候,开始运行程序时,应该把按钮按回nandflash,因为程序的启动就是在nandflash,他把 ...

  7. ASP.NET Core and .NET Core Library Support

    ASP.NET Core and .NET Core Library Support 详情参见:https://github.com/linezero/NETCoreLibrary/blob/mast ...

  8. 二十二 Python分布式爬虫打造搜索引擎Scrapy精讲—scrapy模拟登陆和知乎倒立文字验证码识别

    第一步.首先下载,大神者也的倒立文字验证码识别程序 下载地址:https://github.com/muchrooms/zheye 注意:此程序依赖以下模块包 Keras==2.0.1 Pillow= ...

  9. Effective C++学习笔记(1)

    最近刚看完Effective C++,记录一下当前几个比较常用的方法. 1.以独立语句将newed对象置入智能指针 智能指针是以对象管理资源,在构造函数中获得资源并在析构函数中释放资源​ 以下调用:​ ...

  10. 【转】ubuntu下如何将笔记本自带的键盘关闭

    想必大家都经历过这样的情况:在使用usb接口的外接键盘的时候,很容易按到笔记本自带的键盘,从而导致输入错误.尤其是你将外接键盘放在笔记本键盘上面的时候.怎么解决这个问题呢? 搜索之后,找到了答案.注意 ...