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. nginx 源码阅读 core

    ngx_config.h 数据对齐 #define ngx_align(d, a)     (((d) + (a - 1)) & ~(a - 1)) ngx_core.h #define ng ...

  2. DL开源框架Caffe | 模型微调 (finetune)的场景、问题、技巧以及解决方案

    转自:http://blog.csdn.net/u010402786/article/details/70141261 前言 什么是模型的微调?   使用别人训练好的网络模型进行训练,前提是必须和别人 ...

  3. VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) B. Work Group 树形dp

    题目链接: http://codeforces.com/problemset/problem/533/B B. Work Group time limit per test2 secondsmemor ...

  4. QQueue与QStack使用

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QQueue与QStack使用     本文地址:http://techieliang.com ...

  5. 第四周PSP &进度条

    团队项目PSP 一:表格     C类型 C内容 S开始时间 E结束时间 I时间间隔 T净时间(mins) 预计花费时间(mins) 讨论 讨论开发环境.工具以及技术 8:37 10:42 25 10 ...

  6. 为何php curl post模式发送数据速度变慢了?我来说说原因

    事例: 今天要向一台服务器上传文件,原版是curl的get模式,现在改用了post模式,按照原本的思想,代码如下 <?php $post['c'] = 'config'; $post['t'] ...

  7. mysql & vs2013

    一 mysql 版本介绍 在mysql的官网http://dev.mysql.com/上,mysql 大致分为两个版本,即免费的社区版(community)和 付费的商业版(commercial).其 ...

  8. Maven 项目依赖 pom 文件模板

    下面是网上down的 pom 文件模板: <!-- 属性 --> <properties> <spring.version>4.2.4.RELEASE</sp ...

  9. collection 多态 会自动转型为子类 继承多态需要显示转型

  10. BZOJ 1177 Oil(特技枚举)

    对于三个正方形的位置一共有六种情况. 预处理出(i,j)左上角,左下角,右上角,右下角区域内最大权值的正方形. 枚举分界线更新答案. 刚开始想了一个错误的DP也是蠢啊. #include<set ...