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位客人,每位客人有两种想要吃的点心,你可以安排他们进场的顺序,每位客人会吃掉所有他想要吃的,并且还没被吃掉的点心.如果客 ...
随机推荐
- 算法寒假实习面试经过之 十一贝(offer) 联想研究院(电话一面 被拒)
联想研究院 1面 自我介绍 聊比赛,讲了讲jdd的. 感觉都快要背过了... 之前重复的问题就不说了,说一下印象比较深的 adaboost 与gbdt的区别 随机森林,如果有t个特征,n个树,每个树深 ...
- Confluent介绍
Building a Scalable ETL Pipeline in 30 Minutes confluent介绍: LinkedIn有个三人小组出来创业了—正是当时开发出Apache Kafka实 ...
- 【LeetCode】最大子阵列 Maximum Subarray(贪婪&分治)
描述: Given an integer array nums, find the contiguous subarray (containing at least one number) which ...
- jsp导出
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- Ubuntu 12.04下boost库的交叉编译
oost Ver: 1.55.0Compiler : GNU gcc 4.6 for ARM 1. 确保ARM编译成功安装,并配置好环境变量.2. 解压boost压缩包 3. 进入目录执行./boot ...
- 常用模块-----configparser & subprocess
configparser 模块 功能:操作模块类的文件,configparser类型文件的操作类似于字典,大多数用法和字典相同. 新建文件: import configparser cfg=confi ...
- 初识python---简介,简单的for,while&if
一编程语言:编程语言是程序员与计算机沟通的介质: 编程语言的分类: 1机器语言:是用二进制代码表示的计算机能直接识别和执行的一种机器指令的集合. 优点:灵活,直接执行和速度快 ...
- kvm初体验——linux之kvm安装及使用qemu工具安装系统【转】
本文转载自:https://blog.csdn.net/Heimerdinger_Feng/article/details/79119445 一.安装虚拟机之前先升级软件仓库 sudo apt-get ...
- linux 安装tomcat7
wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.81/bin/apache-tomcat-7.0.81.tar.gz 解压安装包 t ...
- Spark 总结2
网页访问时候 没有打开 注意防火墙! 启动park shell bin下面的spark-shell 这样启动的是单机版的 可以看到没有接入集群中: 应该这么玩儿 用park协议 spark:/ ...