Codeforces Round #423 C. String Reconstruction
来源:互联网 发布:扬州网络电视台节目单 编辑:程序博客网 时间:2024/06/05 06:37
题目链接: String Reconstruction
题目大意
猜一个字符串, 告诉你n个子串, 告诉你这些子串在原字符串出现的次数和出现的位置, 求字典序最小的原字符串
数据规模:
思路
因为题目数据比较大, 如果纯暴力会TLE, 但原字符串长度
使用一个类似与并查集的par数组和find()函数, par[x]记录的是下一个需要更新的位置, par[x]==x代表这个位置还没有更新, 每次更新完s[x]后, 让par[x] = x+1, find(x)可以找到已经更新的最远位置+1, 然后利用路径压缩减少复杂度
代码
#include <bits/stdc++.h>using namespace std;const int MAXN = 5E6;char s[MAXN], t[MAXN];int par[MAXN];int find(int x) { return x == par[x] ? x : par[x]=find(par[x]); }int main(){ int n, m, x, ma = 0; for(int i=0; i<MAXN; ++i) par[i] = i; scanf("%d", &n); while(n--) { scanf("%s%d", t, &m); int len = strlen(t); while(m--) { scanf("%d", &x); --x; ma = max(ma, x+len); int y = x; while((y=find(y)) < x+len) { s[y] = t[y-x]; par[y] = y+1; } } } for(int i=0; i<ma; ++i) putchar(s[i] ? s[i] : 'a'); cout << endl; return 0;}
阅读全文
0 0
- Codeforces Round #423 C. String Reconstruction
- Codeforces Round #423 C. String Reconstruction
- Codeforces Round #423 (Div. 2) C. String Reconstruction(字符串)
- Codeforces Round #423 (Div. 2) C. String Reconstruction
- Codeforces #423-Div. 2-C. String Reconstruction
- Codeforces Round #423 (Div. 2) C. String Reconstruction(思维 模拟)
- Codeforces Round #423 (Div. 2) C String Reconstruction 并查集
- Codeforces Round #423 (Div. 2) C. String Reconstruction思维 D. High Load 构造
- CodeForces 828C String Reconstruction
- Codeforces 828 C String Reconstruction
- codeforces 828C. String Reconstruction
- Codeforces 828 C. String Reconstruction 思维
- CodeForces 828C String Reconstruction(思维)
- CF 423 C : String Reconstruction
- String Reconstruction CodeForces
- codeforces 828 c String Reconstruction(扫描线+string)
- CF Round #423 Div. 2 C. String Reconstruction D. High Load 【思维】
- Codeforces 828C String Reconstruction【思维+并查集】
- Linux环境下Strom单机安装详解
- 数组归并排序
- 利用结巴分词的Python版本实现分词并统计词频
- Android Glide图片加载框架详解
- stm32 rtc 误差实验
- Codeforces Round #423 C. String Reconstruction
- IIS应用程序池自动回收问题的有效解决办法
- Java 常用的时间算法 返回时间集合 时间差 返回加N天后的日期 判断是否同一天
- Java开发中的23种设计模式详解
- 【Deep Learning】相关杂文
- Linux命令行——free命令详解
- 分布式缓存技术redis学习系列(三)——redis高级应用(主从、事务与锁、持久化)
- Dockerfile编写制作含有node环境的项目镜像
- mvn配置settings文件