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 ...
随机推荐
- 多项式函数插值:全域多项式插值(一)单项式基插值、拉格朗日插值、牛顿插值 [MATLAB]
全域多项式插值指的是在整个插值区域内形成一个多项式函数作为插值函数.关于多项式插值的基本知识,见“计算基本理论”. 在单项式基插值和牛顿插值形成的表达式中,求该表达式在某一点处的值使用的Horner嵌 ...
- 【设置】Nginx配置文件具体配置解释
#定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错误日志定义类型,[ debug | ...
- C# 实现屏幕截屏
//屏幕宽 int iWidth = Screen.PrimaryScreen.Bounds.Width; //屏幕高 int iHe ...
- wprintf或_tprintf不显示中文和乱码问题
1.由于中文问题,宽字节编译时会遇到一些不显示或显示乱码问题 如下列代码: 分别是WIN API写入和读取文件,测试_tprintf就会不显示 #include "stdafx.h&quo ...
- tensorflow显存管理
在运行上面的blog的Tensorflow小程序的时候程序我们会遇到一个问题,当然这个问题不影响我们实际的结果计算,但是会给同样使用这台计算机的人带来麻烦,程序会自动调用所有能调用到的资源,并且全占满 ...
- TestDriven.NET 怎么设置快捷键keyboard shortcut(转)
TestDriven.NET 怎么设置快捷键keyboard shortcut 使用TestDriven.NET 测试的时候,觉得点击鼠标很麻烦是不是?嗯,我也觉得,那么我们来看看怎么设置它的快捷键把 ...
- Impala SQL 语言元素(翻译)[转载]
原 Impala SQL 语言元素(翻译) 本文来源于http://my.oschina.net/weiqingbin/blog/189413#OSC_h2_2 摘要 http://www.cloud ...
- Python2 简明教程
Python 由 Guido Van Rossum 在90年代初创建. 它现在是最流行的语言之一 我喜爱python是因为它有极为清晰的语法,甚至可以说,它就是可以执行的伪代码. 注意: 这篇文章针对 ...
- Jsp获取Java的重定向赋值(String)
Jsp获取Java的重定向赋值(String) Java代码片段: //传递String request.setAttribute("msg", msg); //重定向 reque ...
- servlet+jsp+java实现Web应用
servlet+jsp+java实现Web应用 环境: 1,eclipse 2,tomcat3,eclipse tomcat 插件 开发过程: 1,建立一个Dynamic Web Project 2, ...