http://codeforces.com/contest/828/problem/C

并查集的神奇应用。

#include<bits/stdc++.h>
using namespace std; const int maxn=10000005;
char s[maxn];
string ss[100000];
vector<int> g[100000];
int fa[maxn]; int findfa(int x)
{
if (fa[x]==x) return x;
else return fa[x]=findfa(fa[x]);
} void merge(int u,int v)
{
int f1=findfa(u);
int f2=findfa(v);
if (f1!=f2)
{
fa[f1]=f2;
}
} int main()
{
int n;
scanf("%d",&n);
int ma=0;
for (int i=0;i<n;i++)
{
cin >>ss[i];
int k;
scanf("%d",&k);
int l=ss[i].length();
for (int j=0;j<k;j++)
{
int x;
scanf("%d",&x);
g[i].push_back(x);
if (x+l-1>ma) ma=x+l-1;
}
}
s[ma+1]=0;
for (int i=0;i<=ma+1;i++) fa[i]=i;
for (int i=0;i<n;i++)
{
for (int j=0;j<g[i].size();j++)
{
int p=g[i][j];
for (int k=findfa(p);k<=p+ss[i].length()-1;k=findfa(k+1))
{
s[k]=ss[i][k-p];
merge(k,p+ss[i].length());
}
}
}
for (int i=1;i<=ma;i++)
if (s[i]==0) s[i]='a';
printf("%s",s+1);
return 0;
}

[CodeForces]String Reconstruction的更多相关文章

  1. 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 ...

  2. Codeforces - 828C String Reconstruction —— 并查集find()函数

    题目链接:http://codeforces.com/contest/828/problem/C C. String Reconstruction time limit per test 2 seco ...

  3. Codeforces C - String Reconstruction

    C - String Reconstruction 方法一:把确定的点的父亲节点设为下一个点,这样访问过的点的根节点都是没访问过的点. 代码: #include<bits/stdc++.h> ...

  4. CodeForces - 828C String Reconstruction 并查集(next跳)

    String Reconstruction Ivan had string s consisting of small English letters. However, his friend Jul ...

  5. Educational Codeforces Round 94 (Rated for Div. 2) String Similarity、RPG Protagonist、Binary String Reconstruction、Zigzags 思维

    题目链接:String Similarity 题意: 首先题目定义了两个串的相似(串的构成是0.1),如果两个串存在对于一个下标k,它们的值一样,那么这两个串就相似 然后题目给你一个长度为2n-1的串 ...

  6. Codeforces828 C. String Reconstruction

    C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. CF1400-C. Binary String Reconstruction

    CF1400-C. Binary String Reconstruction 题意: 对于一个二进制字符串\(s\),以及一个给定的\(x\),你可以通过一下操作来得到字符串\(w\): 对于字符串\ ...

  8. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

  9. codeforces 828 C. String Reconstruction(思维+优先队列)

    题目链接:http://codeforces.com/contest/828/problem/C 题解:有点意思的题目,可用优先队列解决一下具体看代码理解.或者用并查集或者用线段树都行. #inclu ...

随机推荐

  1. Python异常(基础) except

    为什么要异常处理机制:在程序调用层数较深时,向主调函数传递错误信息需要层层return 返回比较麻烦,用异常处理机制可以较简单的传送错误信息 什么是错误 错误是指由于逻辑或语法等导致一个程序已无法正常 ...

  2. Java反编译插件

    一.eclipse->help->Eclipse Marketplace 如下图:搜索JadClipse,install进行下载安装,

  3. loadrunner处理https请求

    录制到的脚本如下: login() { lr_think_time(10); web_url("verifycode.jsp", "URL=https://192.168 ...

  4. Pythagorean Triples毕达哥斯拉三角(数学思维+构造)

    Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pytha ...

  5. SQLSERVER 根据身份证号码 往出生年月日 赋值

    update CREW_SailorInfo set DT_DOB= ( case then , ) then , ) else null end) 注:此问题仅供参考 如有疑问 请加QQ群18153 ...

  6. 20181120-6 Beta阶段第2周/共2周 Scrum立会报告+燃尽图 03

    此作业要求参见:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2411] 版本控制地址    [https://git.coding.n ...

  7. 用VS测试程序

    怀着一种忐忑的心情,我开始了我的软件测试. #include "stdio.h" #include "stdlib.h" int main(int argc, ...

  8. 20135208 JAVA第三次实验

    课程:Java实验   班级:201352     姓名:贺邦  学号:20135208 成绩:             指导教师:娄佳鹏   实验日期:15.06.03 实验密级:         ...

  9. oracle与DB2的一些架构

    首先,我们需要理解 Oracle 使用的架构,并理解它与 DB2 的不同之处.图 1 展示了 Oracle 的系统结构.将该图与 图 2 进行比较,后者显示了 DB2 的系统结构.在阅读本文的时候,为 ...

  10. NFS 它的目的就是想让不同的机器、不同的作业系统可以彼此分享个别的档案啦

    NFS即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件, ...