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. ARM的Trust Zone技术

    ARM的Trust_Zone技术是一个系统的Access Control的架构. 与AXI,AHB,APB其中的secure,supervisor信号相关联. 与ARM core的模式相关连,当ARM ...

  2. 修改form 的字段背景颜色及字体颜色

    1.通过个性化实现 2. 修改form 代码 有一张工资单,当某个员工的工资超过5000时,用户需要系统能用红色来指示员工的姓名和工资. 实现方法: 我们新做一张form,按常规建好block和ite ...

  3. Python 读写文件中w与wt, r与rt的区别

    w和wt是一们的,r和rt是一样的,t是默认参数,可以省略的,help(open)就能看到open的参数的详细说明. w,r,wt,rt都是python里面文件操作的模式.w是写模式,r是读模式.t是 ...

  4. Python: 合并拼接字符串join()| format() | +

    将几个小字符串合并成为一个大的字符串 1如果合并的是一个序列,最快的方式是使用join()方法 >>> parts = ['Is', 'Chicago', 'Not', 'Chica ...

  5. Linux基础命令---head

    head 显示文件开头的几行,默认显示10行,可以使用选项-n来指定行数.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1.语法   ...

  6. 如何禁用MySql总是定时弹出一个MySQLInstallerConsole.exe的窗口

    如何禁用MySql总是定时弹出一个MySQLInstallerConsole.exe的窗口 禁用mysql总是弹出一个安装框的定时任务这一条安装命令,Installing MySQL 5.6.21 u ...

  7. 02: DOM 实例

    1.1 Event 对象 <body> <a id="myAnchor" href="http://www.microsoft.com"> ...

  8. oracle一些工作笔记

    表空间: oracle表空间对应的数据文件: SELECT t1.name, t2.name FROM v$tablespace t1, v$datafile t2 WHERE t1.ts#=t2.t ...

  9. 自定义LisetView

    1.ListView listview=findViewById(R.id.listview); 2.public class MyAdapter extends BaseAdapter{ priva ...

  10. Python3基础 str title 单词首字母大写,其余均为小写

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...