Codeforces C - String Reconstruction
方法一:把确定的点的父亲节点设为下一个点,这样访问过的点的根节点都是没访问过的点。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+;
char s[N],res[N*];
int fa[N*];
int Find(int x)
{
return x==fa[x]?x:fa[x]=Find(fa[x]);
}
int main()
{
for(int i=;i<N*;i++)fa[i]=i;
int n,t,x;
scanf("%d",&n);
int ml=;
for(int i=;i<n;i++)
{
scanf("%s",s);
scanf("%d",&t);
int l=strlen(s);
while(t--)
{
scanf("%d",&x);
ml=max(ml,l+x-);
int y=x;
while((y=Find(y))<=l+x-)
{
res[y]=s[y-x];
fa[y]=y+;
}
}
}
for(int i=;i<=ml;i++)if(!res[i])res[i]='a';
puts(res+);
return ;
}
方法二:把所有点放进set容器里,拜访过的点就删掉。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+;
char s[N],res[N*];
set<int>ss;
int main()
{
ios::sync_with_stdio(false);
cin.tie();
for(int i=;i<N*;i++)ss.insert(i);
int n,t,a;
cin>>n;
int ml=;
for(int i=;i<n;i++)
{
cin>>s;
cin>>t;
int l=strlen(s);
while(t--)
{
cin>>a;
while()
{
set<int>::iterator it=ss.lower_bound(a);
if(it==ss.end()||*it-a>=l)break;
ml=max(ml,*it);
res[*it]=s[*it-a];
ss.erase(it);
}
}
}
for(int i=;i<ml+;i++)if(!res[i])res[i]='a';
puts(res+);
return ;
}
Codeforces C - String Reconstruction的更多相关文章
- 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 828C String Reconstruction(并查集思想)
题意:给你n个串,给你每个串在总串中开始的每个位置,问你最小字典序总串. 思路:显然这道题有很多重复填涂的地方,那么这里的时间花费就会特别高. 我们维护一个并查集fa,用fa[i]记录从第i位置开始第 ...
- Codeforces 828C String Reconstruction【并查集巧妙运用】
LINK 题目大意 给你n个串和在原串中的出现位置,问原串 思路 直接跑肯定是GG 考虑怎么优化 因为保证有解,所以考虑过的点我们就不再考虑 用并查集维护当前每个点之后最早的没有被更新过的点 然后就做 ...
- 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 ...
- 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]String Reconstruction
http://codeforces.com/contest/828/problem/C 并查集的神奇应用. #include<bits/stdc++.h> using namespace ...
随机推荐
- OO第三次阶段性总结
一.规格化设计的历史以及人们重视的原因 发展历史 从20世纪60年代开始,就存在着许多不同的形式规格说明语言和软件开发方法.在形式规格说明领域一些最主要的发展过程列举如下: 1969-1972 C.A ...
- Nhibernate入门与demo
学习和使用Nhibernate已经很久了,一直想写点东西和大家一起学习使用Nhibernate.博客园里也有很多大牛写了很多关于Nhibernate入门的文章.其中:李永京的博客http://www. ...
- OAuth 白话简明教程 1.简述
转自:http://www.cftea.com/c/2016/11/6702.asp OAuth 白话简明教程 1.简述 OAuth 白话简明教程 2.授权码模式(Authorization Code ...
- mysql的Navicat查看数据库的ER图
1.mysql数据库表间的关系图可以通过navicat查看.
- Ajax—web中ajax的常用方式
什么Web2.0的特点? 1:注重用户贡献度 2:内容聚合RSS协议(每小块都个性化,单独加载单独请求,不用全部刷新--Ajax) 3:更丰富的用户体验 Ajax的概念? "Asynchro ...
- [转]使用C#开发ActiveX控件全攻略
前言: 这段时间因为工作的需要,研究了一下ActiveX控件.总结如下: 先说说ActiveX的基本概念. 根据微软权威的软件开发指南MSDN(Microsoft Developer Network) ...
- Python: 序列: 过滤序列元素
问题: 你有一个数据序列,想利用一些规则从中提取出需要的值或者是缩短序列 answer: eg1:列表推导 最简单的过滤序列元素的方法就是使用列表推导.比如:>>> mylist = ...
- Google、亚马逊、微软 、阿里巴巴开源软件一览
Google.亚马逊.微软 .阿里巴巴开源软件一览 大公司为什么要发布开源项目?一是开源能够帮助他人更快地开发软件,促进世界创新,主要是社会价值层面的考虑.二是开源能够倒逼工程师写出更好的代码.三是开 ...
- SpringBoot之统一异常处理
异常,不仅仅是程序运行状态的描述,还可以使得代码编写更加的规范 1.自定义异常:FieldValueInvalidException package com.geniuses.sewage_zer ...
- iOS开发之AFNetworking实现数据传输和文件上传
//传输数据 1 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.r ...