CodeForces - 827A:String Reconstruction (基础并查集)
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one.
Ivan knows some information about the string s. Namely, he remembers, that string tioccurs in string s at least ki times or more, he also remembers exactly ki positions where the string ti occurs in string s: these positions are xi, 1, xi, 2, ..., xi, ki. He remembers n such strings ti.
You are to reconstruct lexicographically minimal string s such that it fits all the information Ivan remembers. Strings ti and string s consist of small English letters only.
Input
The first line contains single integer n (1 ≤ n ≤ 105) — the number of strings Ivan remembers.
The next n lines contain information about the strings. The i-th of these lines contains non-empty string ti, then positive integer ki, which equal to the number of times the string ti occurs in string s, and then ki distinct positive integers xi, 1, xi, 2, ..., xi, ki in increasing order — positions, in which occurrences of the string ti in the string s start. It is guaranteed that the sum of lengths of strings ti doesn't exceed 106, 1 ≤ xi, j ≤ 106, 1 ≤ ki ≤ 106, and the sum of all ki doesn't exceed 106. The strings ti can coincide.
It is guaranteed that the input data is not self-contradictory, and thus at least one answer always exists.
Output
Print lexicographically minimal string that fits all the information Ivan remembers.
Examples
3
a 4 1 3 5 7
ab 2 1 5
ca 1 4
abacaba
1
a 1 3
aaa
3
ab 1 1
aba 1 3
ab 2 3 5
ababab
题意:给定一个字符串的部分消息,让你将其补齐,并且字典序最小。
思路:给出的消息可以得到字符串长度。现在就说需要把给出的消息都填进去,没有填到的部分用‘a’补齐,给出的消息很多重复的,直接for是不想的,我们用并查集快速的得到后面的第一个空着的位置。
(常规操作,居然想不到。。。
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
char c[maxn]; int ans[maxn],fa[maxn];
int find(int x){
if(x!=fa[x]) fa[x]=find(fa[x]);
return fa[x];
}
int main()
{
int N,L=;
scanf("%d",&N);
rep(i,,2e6) fa[i]=i;
rep(i,,N){
scanf("%s",c+);
int Len=strlen(c+),num; scanf("%d",&num);
rep(j,,num){
int x,pos; scanf("%d",&x); L=max(L,x+Len-);
pos=x; while(true){
pos=find(pos);
if(pos>x+Len-||!pos) break;
ans[pos]=c[pos-x+];
fa[pos]=fa[find(pos+)];
pos=fa[pos];
}
}
}
rep(i,,L){
if(ans[i]=='\0') ans[i]='a';
putchar(ans[i]);
}
return ;
}
CodeForces - 827A:String Reconstruction (基础并查集)的更多相关文章
- CodeForces 828C String Reconstruction(并查集思想)
题意:给你n个串,给你每个串在总串中开始的每个位置,问你最小字典序总串. 思路:显然这道题有很多重复填涂的地方,那么这里的时间花费就会特别高. 我们维护一个并查集fa,用fa[i]记录从第i位置开始第 ...
- Codeforces 828C String Reconstruction【并查集巧妙运用】
LINK 题目大意 给你n个串和在原串中的出现位置,问原串 思路 直接跑肯定是GG 考虑怎么优化 因为保证有解,所以考虑过的点我们就不再考虑 用并查集维护当前每个点之后最早的没有被更新过的点 然后就做 ...
- String Reconstruction (并查集)
并查集维护和我这个位置的字母连续的已经被填充的字母能到达的最右边的第一个还没有填充的位置,然后把这个位置填上应该填的东西,然后把这个位置和下一个位置连接起来,如果下一个位置还没有填,我就会把下一个位置 ...
- hdu 1829 基础并查集,查同性恋
A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- 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 731C:Socks(并查集)
http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,m天,k个颜色,每个袜子有一个颜色,再给出m天,每天有两只袜子,每只袜子可能不同颜色,问 ...
- Codeforces 859E Desk Disorder:并查集【两个属性二选一】
题目链接:http://codeforces.com/problemset/problem/859/E 题意: 有n个人,2n个座位. 给出这n个人初始的座位,和他们想坐的座位. 每个人要么坐在原来的 ...
- CodeForces - 1209D Cow and Snacks 并查集
CodeForces - 1209D 题意 现在n种点心,每种点心只有一份,有k位客人,每位客人有两种想要吃的点心,你可以安排他们进场的顺序,每位客人会吃掉所有他想要吃的,并且还没被吃掉的点心.如果客 ...
随机推荐
- loadrunder之脚本篇——加密解密
密码加密 可以给密码加密,意在把结果字符串作为脚本的参数或者参数值.例如,完整可能有一个用户密码填写的表单,你想测试网站针对不同密码的反应,但是你又想保护密码的安全.Password Encoder允 ...
- DEC VT100 terminal
- [POI2009]Wie
题目 BZOJ 虽然是解压题但也学到了简洁的码风 做法 \(dijkstra\)跑动规 My complete code #include<bits/stdc++.h> #include& ...
- jQuery横向图片手风琴
在线演示 本地下载
- awk的控制语句
本章主要讲actions中的控制语句,和C语言的控制语句类似. 1.选择语句 if (condition) then-body else else-body 2.循环语句之while: while ( ...
- h => h(App)解析
在创建Vue实例时经常看见render: h => h(App)的语句,现做出如下解析: h即为createElement,将h作为createElement的别名是Vue生态系统的通用管理,也 ...
- Pandas的 loc iloc ix 区别
先看代码: In [46]: import pandas as pd In [47]: data = [[1,2,3],[4,5,6]] In [48]: index = [0,1] In [49]: ...
- Ubuntu 配置NTP Server
Ubuntu安装NTP Server很简单,分位3步走: 第一步:安装NTP root@cephadmin:~/ceph-cluster# apt-get install ntp Reading pa ...
- mongodb的使用(入门)
1.登录mongodb ./bin/mongo 2.查看所有数据库 show dbs ##默认有admin 和 local两个库 3.创建数据库 use test #创建数据库后,如果不写入数据 ...
- mysql基础(2)-数据处理(mysql+pandas)
插入语句insert insert 数据表名(字段名...) values(字段值): 例 : insert into new_student values("张"," ...