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的更多相关文章

  1. Codeforces - 828C String Reconstruction —— 并查集find()函数

    题目链接:http://codeforces.com/contest/828/problem/C C. String Reconstruction time limit per test 2 seco ...

  2. CodeForces - 828C String Reconstruction 并查集(next跳)

    String Reconstruction Ivan had string s consisting of small English letters. However, his friend Jul ...

  3. CodeForces 828C String Reconstruction(并查集思想)

    题意:给你n个串,给你每个串在总串中开始的每个位置,问你最小字典序总串. 思路:显然这道题有很多重复填涂的地方,那么这里的时间花费就会特别高. 我们维护一个并查集fa,用fa[i]记录从第i位置开始第 ...

  4. Codeforces 828C String Reconstruction【并查集巧妙运用】

    LINK 题目大意 给你n个串和在原串中的出现位置,问原串 思路 直接跑肯定是GG 考虑怎么优化 因为保证有解,所以考虑过的点我们就不再考虑 用并查集维护当前每个点之后最早的没有被更新过的点 然后就做 ...

  5. 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 ...

  6. Educational Codeforces Round 94 (Rated for Div. 2) String Similarity、RPG Protagonist、Binary String Reconstruction、Zigzags 思维

    题目链接:String Similarity 题意: 首先题目定义了两个串的相似(串的构成是0.1),如果两个串存在对于一个下标k,它们的值一样,那么这两个串就相似 然后题目给你一个长度为2n-1的串 ...

  7. Codeforces828 C. String Reconstruction

    C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. CF1400-C. Binary String Reconstruction

    CF1400-C. Binary String Reconstruction 题意: 对于一个二进制字符串\(s\),以及一个给定的\(x\),你可以通过一下操作来得到字符串\(w\): 对于字符串\ ...

  9. [CodeForces]String Reconstruction

    http://codeforces.com/contest/828/problem/C 并查集的神奇应用. #include<bits/stdc++.h> using namespace ...

随机推荐

  1. STA分析(五) parastics

    互联线的寄生参数 一般一个cell或者block的连接pin就叫做一个net.在物理实现的时候,一条net可能会穿过几层metal,因为每个metal层的电阻,电容值都不一样.所以,在分析 net的寄 ...

  2. readyState与status

    XMLHttpRequest对象(Ajax)的状态码(readystate) 当一个XMLHttpRequest初次创建时,这个属性的值是从0开始,知道接收完整的HTTP响应,这个值增加到4.有五种状 ...

  3. Linux基础命令---tune2fs

    tune2fs tune2fs允许系统管理员在Linux ext2.ext3或ext4文件系统上调整各种可调的文件系统参数.这些选项的当前值可以使用-l选项显示,也可以通过使用dumpe2fs (8) ...

  4. MySQL Crash Course #05# Chapter 9. 10. 11. 12 正则.函数. API

    索引 正则表达式:MySQL only supports a small subset of what is supported in most regular expression implemen ...

  5. 20145304 Exp7 网络欺诈技术防范

    20145304 Exp7 网络欺诈技术防范 实验后回答问题 1.通常在什么场景下容易受到DNS spoof攻击 在公共网络下,如一些购物场所.咖啡馆.快餐店等提供的网络下:当自己常使用的无线网被有恶 ...

  6. 20145329 《网络对抗技术》浏览器MS11_050安全漏洞攻击

    两台虚拟机: kali ip:192.168.96.130 windows xp sp3(包含IE7)ip:192.168.96.128 1.在kali终端中开启msfconsole. 2.进入漏洞模 ...

  7. 对于phy芯片的认识

    一,关于phy芯片 以RTL8211E(G)为例 PHY是IEEE802.3中定义的一个标准模块,STA(station management entity,管理实体,一般为MAC或CPU) 通过SM ...

  8. Educational Codeforces Round 21 Problem D(Codeforces 808D)

    Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...

  9. sqlite3 的一些整理和补充

    一,sqlite3数据库打开时的返回值及其所代表的含义 返回值 描述 返回值 描述 SQLITE_OK=0 返回成功 SQLITE_FULL=13 数据库满,插入失败 SQLITE_ERROR=1 S ...

  10. 【前端】javascript+jquery实现手风琴式的滚动banner或产品展示图

    实现效果 实现步骤 // 鼠标放入到li中该盒子变宽,其他盒子变窄,鼠标移开大盒子,恢复原样 // 实现步骤 // 1. 给li添加背景 // 2. 绑定onmouseover事件,鼠标放入到li中, ...