Codeforces 828 C. String Reconstruction 思维
来源:互联网 发布:网络用语开屏什么意思 编辑:程序博客网 时间:2024/06/05 04:58
传送门:C. String Reconstruction
题意:给定n个子串,和每个子串在原串中的出现位置(每个子串可能出现多次),问字典序最小的原串是什么。
思路:这题暴力3分钟就写完了,然而并不敢交,想了很长时间的优化也就想到了记录每个位置的结束点,然并卵,大数据该T还是T。
正解:利用类似并查集寻根函数的思想维护区间端点,以前做过类似的题的,昨晚不知为啥脑抽就是想不起来。。
PS:不加并查集的路径压缩,直接一个next数组也是能水过的。
代码:
#include<bits/stdc++.h>#define ll long long#define pi acos(-1)#define MAXN 100010#define inf 0x3f3f3f3fusing namespace std;typedef pair<int,int>P;char ans[MAXN*100];char s[MAXN*10];int f[MAXN*100];int getf(int k){ return k==f[k]?k:f[k]=getf(f[k]);}int main(){int n,k,LEN=0,id;cin>>n;for(int i=0;i<MAXN*100;i++)f[i]=i;for(int i=0;i<n;i++){scanf("%s %d",s,&k);int len=strlen(s);while(k--){scanf("%d",&id);for(int i=getf(id);i<id+len;i=f[i]=getf(i+1)){ans[i]=s[i-id];}LEN=max(LEN,id+len);}}for(int i=1;i<LEN;i++){if(ans[i]=='\0')ans[i]='a';}puts(ans+1); return 0;}
阅读全文
0 0
- Codeforces 828 C. String Reconstruction 思维
- CodeForces 828C String Reconstruction(思维)
- Codeforces 828C String Reconstruction【思维+并查集】
- CodeForces 828C String Reconstruction
- Codeforces 828 C String Reconstruction
- codeforces 828C. String Reconstruction
- codeforces 828 c String Reconstruction(扫描线+string)
- Codeforces Round #423 (Div. 2) C. String Reconstruction(思维 模拟)
- Codeforces Round #423 (Div. 2) C. String Reconstruction思维 D. High Load 构造
- Codeforces #423-Div. 2-C. String Reconstruction
- Codeforces Round #423 C. String Reconstruction
- Codeforces Round #423 C. String Reconstruction
- String Reconstruction CodeForces
- Codeforces 827A/828C String Reconstruction[线段树单点更新]
- Codeforces Round #423 (Div. 2) C. String Reconstruction(字符串)
- Codeforces Round #423 (Div. 2) C. String Reconstruction
- Codeforces #848C: String Reconstruction 题解之花样虐题
- CF 828C String Reconstruction(暴力)
- 数据库原理 、 SQL(DDL、DML)
- VS2008项目属性的部分解释
- 文章标题
- JavaScript全栈开发-工具篇
- mysqlbinlog: unknown variable 'default-character-set=utf8'
- Codeforces 828 C. String Reconstruction 思维
- POJ 3184 Finicky Grazers 笔记
- 备忘录----------下拉框选择触发事件
- C++中两个线程用同一个list进行数据传递
- Windows 编译caffe常见错误问题汇总
- meta 头部信息
- 预处理,编译,链接过程
- Spring Security 实现权限登陆配置
- Linux 下route命令详解