[CodeForces]String Reconstruction
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的更多相关文章
- 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 ...
- Codeforces - 828C String Reconstruction —— 并查集find()函数
题目链接:http://codeforces.com/contest/828/problem/C C. String Reconstruction time limit per test 2 seco ...
- Codeforces C - String Reconstruction
C - String Reconstruction 方法一:把确定的点的父亲节点设为下一个点,这样访问过的点的根节点都是没访问过的点. 代码: #include<bits/stdc++.h> ...
- CodeForces - 828C String Reconstruction 并查集(next跳)
String Reconstruction Ivan had string s consisting of small English letters. However, his friend Jul ...
- Educational Codeforces Round 94 (Rated for Div. 2) String Similarity、RPG Protagonist、Binary String Reconstruction、Zigzags 思维
题目链接:String Similarity 题意: 首先题目定义了两个串的相似(串的构成是0.1),如果两个串存在对于一个下标k,它们的值一样,那么这两个串就相似 然后题目给你一个长度为2n-1的串 ...
- Codeforces828 C. String Reconstruction
C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- CF1400-C. Binary String Reconstruction
CF1400-C. Binary String Reconstruction 题意: 对于一个二进制字符串\(s\),以及一个给定的\(x\),你可以通过一下操作来得到字符串\(w\): 对于字符串\ ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- codeforces 828 C. String Reconstruction(思维+优先队列)
题目链接:http://codeforces.com/contest/828/problem/C 题解:有点意思的题目,可用优先队列解决一下具体看代码理解.或者用并查集或者用线段树都行. #inclu ...
随机推荐
- Python基础灬高阶函数(lambda,filter,map,reduce,zip)
高阶函数 lambda函数 关键字lambda表示匿名函数,当我们在传入函数时,有些时候,不需要显式地定义函数,直接传入匿名函数更方便. lambda函数省略函数名,冒号前为参数,冒号后函数体. # ...
- Powershell按文件最后修改时间删除多余文件
Powershell按文件最后修改时间删除多余文件 1. 删除目录内多余文件,目录文件个数大于$count后,按最后修改时间倒序排列,删除最旧的文件. Sort-Object -Property La ...
- 3. IP地址转换函数
一.字符串表示的IP地址需要被转化为整数(二进制数)方能使用 IPv4地址:点分十进制字符串 IPv6地址:十六进制字符串 有时(如记录日志),我们则要把整数(二进制数)表示的IP地址转化为可读的字符 ...
- Scrum立会报告+燃尽图(十月二十六日总第十七次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2246 项目地址:https://git.coding.net/zhang ...
- 安装VS的过程
软件工程学习到第三周,我们需要下载一个新的软件,用来进行软件测试.刚开始知道的时候觉得没甚么,不就是下个软件吗!有什么大不了的,分分钟搞定的事.可是想象很美好,现实很骨感.这是一个巨大的工作量呀,不仅 ...
- 关于双系统下Ubuntu不能访问Windows中某个盘的问题
1.问题描述 在Ubuntu系统下访问Windows系统中磁盘时出现无法访问的情况,具体如下显示: 该问题为磁盘挂载错误,需要进行修复. 2.解决办法 (1)打开终端:如果没有安装ntfs ...
- Microsoft Orleans 之安装
先决条件 Orleans 是一个.net 类库集,为了使用它,你需要.net 4.5.1 或者更高版本,开发工具集需要visual studio 2015 或者更高版本或者其他支持的开发工具,不支持V ...
- vsftpd 安全性能工具
vsftpd实战(服务端192.168.23.12,客户端192.168.23.11) 1:安装vsftpdyum install -y vsftpd 2:客户端安装lftpyum install - ...
- 服务器BMC(带外)
服务器除了装linux,windows系统外,相应还有一个可通过网线(服务器默认带外地址--可改)连接具体厂商服务器的BMC(Baseboard Management Controller,基板管理控 ...
- 【第八周】【新蜂】新NABCD
由小组成员宫成荣撰写 一.小组项目申请时提交的NABCD: 痛点:普通的俄罗斯方块是不现实距离下一级有多远的,我们的游戏能显示距离下一等级游戏有多远.方便玩家体验. nabc: n:能满足大多数玩家的 ...