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 是不是在同一集合中. 析:很容易知道是用并 ...
随机推荐
- Windows中使用wget整站下载
weget wget安装 Windows下载 点击下载 https://eternallybored.org/misc/wget/ 会跳转到wget的下载页,根据自己电脑选择下载的文件,我下载的版 ...
- Ngix
Ngix安装 官网地址,下载为源码,需要编译安装 http://nginx.org/ 环境 1.需要安装gcc的环境. yum install gcc-c++ 2.第三方的开发包. PCRE PCRE ...
- DSP基础学习-ADC采样
DSP基础学习-ADC采样 彭会锋 2015-04-27 22:30:03 在查看ADC采样例程的时候我发现了下面的代码挺有意思的 EALLOW; GpioCtrlRegs.GPAMUX2.bit.G ...
- asp.net服务器上无法发送邮件的问题
前几天为开发的网站做了个发送邮件的功能,但是部署到服务器上无法发送邮件,提示由于目标机器积极拒绝,无法连接.在网上找到了一个解决办法 如果安装了McAfee杀毒软件(按照“手工安装方法”安装),首先需 ...
- iptables详解(14):iptables小结之常用套路
不知不觉,已经总结了13篇iptables文章,这些文章中有一些需要注意的地方. 此处,我们对前文中的一些注意点进行总结,我们可以理解为对"常用套路"的总结. 记住这些套路,能让我 ...
- (转载)设置环境变量永久生效和临时生效 export PS1
source/etc/profile是让/etc/profile文件修改后立即生效, 还有一种方法是:. /etc/profile 注意:.和/etc/profile有空格 linux中source命 ...
- 014PHP基础知识——流程控制(二)
<?php /** *switch 分支语句: * switch(表达式){ * case 值1: * ... * break; * * case 值2: * ... * break; * de ...
- DB2导入导出数据
1.导出表数据到txt文件: export to /brcb_edp/data_public_edp/file/CCDM/file/FILE_CCDM_DR_CARD_CUST_DET.txt of ...
- 2017北京赛区H题
题目链接 题意:在n*m的矩阵中选择变换或者不变换一个数变成p,使得最大子矩阵和最小 1<=n,m<=150, -1000<=p<=1000; 题解: 他人题解链接 涉及到知识 ...
- 剑指offer--41.扑克牌顺子
没有判断数组长度,导致{1,3,2,5,4}输出结果是false是什么鬼??? ------------------------------------------------------------ ...