Codeforces 828C String Reconstruction【并查集巧妙运用】
题目大意
给你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【并查集巧妙运用】的更多相关文章
- 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 ...
- CodeForces 828C String Reconstruction(并查集思想)
题意:给你n个串,给你每个串在总串中开始的每个位置,问你最小字典序总串. 思路:显然这道题有很多重复填涂的地方,那么这里的时间花费就会特别高. 我们维护一个并查集fa,用fa[i]记录从第i位置开始第 ...
- 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 Gym 100463E Spies 并查集
Spies Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Desc ...
- Codeforces 650C Table Compression (并查集)
题意:M×N的矩阵 让你保持每行每列的大小对应关系不变,将矩阵重写,重写后的最大值最小. 思路:离散化思想+并查集,详见代码 好题! #include <iostream> #includ ...
- Codeforces 468B Two Sets 并查集
题目大意:给出n个数,要求将n个数分配到两个集合中,集合0中的元素x,要求A-x也再0中,同理1集合. 写了几个版本号,一直WA在第8组数据...最后參考下ans,写了并查集过了 学到:1.注意离散的 ...
- Codeforces 859E Desk Disorder 并查集找环,乘法原理
题目链接:http://codeforces.com/contest/859/problem/E 题意:有N个人.2N个座位.现在告诉你这N个人它们现在的座位.以及它们想去的座位.每个人可以去它们想去 ...
- CodeForces 566D Restructuring Company (并查集+链表)
题意:给定 3 种操作, 第一种 1 u v 把 u 和 v 合并 第二种 2 l r 把 l - r 这一段区间合并 第三种 3 u v 判断 u 和 v 是不是在同一集合中. 析:很容易知道是用并 ...
随机推荐
- POJ 1144 Network(无向图的割顶和桥模板题)
http://poj.org/problem?id=1144 题意: 给出图,求割点数. 思路: 关于无向图的割顶和桥,这篇博客写的挺不错,有不懂的可以去看一下http://blog.csdn.net ...
- 好的Mysql 查询语句
select swr.id,swr.name,swr.sort as type,count(swl.id) as nums,ifnull(sum(swl.package_num),0) package ...
- java的时间获取
System类代表系统,系统级的很多属性和控制方法都放置在该类的内部.该类位于java.lang包. currentTimeMillis方法 public static long currentTim ...
- QT 样式表实例
目标:实现button的圆角效果及背景颜色,鼠标滑过颜色变亮,鼠标点击颜色变重. 总体思路首,先根据需要及样式规则新建.qss文件,然后在代码中将文件引用并应用样式. 具体过程如下: 1在项目当前目录 ...
- 分布式系统中的幂等性-zookeeper与dubbo
现如今我们的系统大多拆分为分布式SOA,或者微服务,一套系统中包含了多个子系统服务,而一个子系统服务往往会去调用另一个服务,而服务调用服务无非就是使用RPC通信或者restful,既然是通信,那么就有 ...
- phalcon: 项目地址/P(.*), 项目地址/Pbaidu 与 路由
phalcon: 项目地址/P(.*) 与 路由 有一个项目地址:因客户渠道不同,带的参数也不相同.当时想到的是伪静态规则,但是发现自己没有那么强大.该走phalcon路由规则,地址如下: www.x ...
- 20165332 2017-2018-2《Java程序设计》课程总结
20165332 2017-2018-2<Java程序设计>课程总结 一.每周作业及实验报告链接汇总 我期望的师生关系 学习基础和c语言基础调查 Linux安装及命令入门 第一周学习总结 ...
- 明明白白AOP
引子: AOP(面向方面编程:Aspect Oriented Programing)和IoC一样是Spring容器的内核,声明式事务的功能在此基础上开花结果.但是AOP和OOP差别较大,要很好地理解这 ...
- python3.6环境部署文档
python3.6环境部署文档 内容 Linux部署Python3.6环境 Mac部署Python3.6环境 Window10部署Python3.6环境 Pycharm安装 1. Linux部署P ...
- 初次安装git配置用户名和邮箱及密钥
在Windows上安装Git: 在Windows上使用Git,可以从Git官网直接下载安装程序,(网速慢的同学请移步国内镜像),然后按默认选项安装即可. 安装完成后 键盘敲上:windows+r你会看 ...