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. Fulfilling Work: The Shippers More entrepreneurs hire 'fulfillment' outfits to store and ship their products

    By Stu Woo June 23, 2011 Brett Teper faced a logistical problem when he and a partner founded ModPro ...

  2. angularjs工作原理解析

    个人觉得,要很好的理解AngularJS的运行机制,才能尽可能避免掉到坑里面去.在这篇文章中,我将根据网上的资料和自己的理解对AngularJS的在启动后,每一步都做了些什么,做一个比较清楚详细的解析 ...

  3. php异步学习(2)

    PHP开启异步多线程执行脚本   场景要求 客户端调用服务器a.php接口,需要执行一个长达5s-20s不等的耗资源操作,但是客户端响应请求时间为5秒(微信公众账号服务器请求响应超时时间),5s以上无 ...

  4. Weighted Median

    For n elements x1, x2, ..., xn with positive integer weights w1, w2, ..., wn. The weighted median is ...

  5. SSH 框架的心得

    使用SSH框架做完了一个普通网站的前后台项目,成热写点心得,免得以后再入坑.其中使用 Strust2  2.3.33 + Spring 4.3.9 + Hibernate 5.2.10 eclipse ...

  6. DB2的编目

    D在DB2数据库中,编目(catalog)这个单词很难理解,我自己当初在学习DB2的时候也常常被这个编目搞的很不明白,直到现在我个人也感觉到DB2中编目(catalog)这个术语用的不是很好,具体来说 ...

  7. 浅谈 Sql Server 游标

    查询语句可能返回多条记录,如果数据量非常大,需要使用游标来逐条读取查询结果集中的记录.应用程序可以根据需要滚动或浏览其中的数据.本篇介绍游标的概念.分类.以及基本操作等内容. 一:认识游标游标是SQL ...

  8. 使用Log4在测试过程中打印执行日志 及配置log4j.properties!

    http://zengxiantao.iteye.com/blog/1881706 1.环境配置:到网上下载log4j-1.2.17.jar包!完后 添加到 项目的build path 中即可! 2. ...

  9. 第188天:extend拷贝创建对象的原理

    一.拷贝创建对象的原理 //拷贝创建对象核心代码 function extend(target,source) { //遍历对象 for(var i in source){ target[i] = s ...

  10. java map 当key相同的时候 最后一个覆盖最近的一个值