题目链接:http://codeforces.com/contest/828/problem/C

题解:有点意思的题目,可用优先队列解决一下具体看代码理解。或者用并查集或者用线段树都行。

#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <cstdio>
#include <map>
#include <string>
#include <vector>
using namespace std;
const int M = 2e6 + 10;
const int N = 1e5 + 10;
int pos;
struct TnT {
int sta, ed , num;
TnT() {}
TnT(int sta , int ed , int num):sta(sta), ed(ed), num(num) {}
bool operator <(const TnT &a) const {
return ed - pos > a.ed - pos;
}
};
priority_queue<TnT>q;
vector<int>vc[M];
string s[N];
int main() {
int n, k, pp;
scanf("%d" , &n);
int Max = 1;
for(int i = 1 ; i <= n ; i++) {
cin >> s[i];
cin >> k;
int len = s[i].size();
for(int j = 0 ; j < k ; j++) {
cin >> pp;
Max = max(Max , pp + len - 1);
vc[pp - 1].push_back(i);
}
}
for(pos = 0 ; pos < Max ; pos++) {
int len = vc[pos].size();
for(int i = 0 ; i < len ; i++) {
int L = s[vc[pos][i]].size();
q.push(TnT(pos , pos + L - 1 , vc[pos][i]));
}
if(q.empty()) cout << 'a';
else {
cout << s[q.top().num][pos - q.top().sta];
while(!q.empty()) {
if(q.top().ed == pos) q.pop();
else break;
}
}
}
cout << endl;
return 0;
}

codeforces 828 C. String Reconstruction(思维+优先队列)的更多相关文章

  1. CodeForces - 827A:String Reconstruction (基础并查集)

    Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...

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

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

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

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

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

  5. Codeforces C - String Reconstruction

    C - String Reconstruction 方法一:把确定的点的父亲节点设为下一个点,这样访问过的点的根节点都是没访问过的点. 代码: #include<bits/stdc++.h> ...

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

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

  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. 【iOS】NSString rangeOfString

    今天遇到了 NSString 的 rangeOfString 方法,刚遇到的时候不知道什么作用, 网上找到了一篇文章,介绍得挺简洁,代码如下: NSString *str1 = @"can ...

  2. Java 设置PDF文档浏览偏好

    在查看PDF文档时,可进行一些浏览偏好设置,例如是否全屏浏览.隐藏或显示菜单栏/工具栏.设置页面布局模式等,下面将通过Java编程的方式来演示如何设置. 使用工具: Free Spire.PDF fo ...

  3. Hyper-V虚拟机上安装Ubuntu16.04/Ubuntu18.04.2LTS,搭建GitLab

    我的电脑系统是win10,内存8g如下 一开始是装的Ubuntu18.04.2LTS, gitlab-ce_12.1.3-ce.0_amd64.deb,每次能够安装成功,但是修改完ip后,运行gitl ...

  4. .lib .dll 区别介绍、使用(dll的两种引入方式)

    .lib .dll文件都是程序可直接引用的文件,前者就是所谓的库文件,后者是动态链接库(Dynamic Link Library)也是一个库文件.而.pdb则可以理解为符号表文件.DLL(Dynami ...

  5. Paxos算法原理

    1.从ACID到CAP 我们知道传统集中式系统中实现ACID是很简单的,在分布式环境中,涉及到不同的节点,节点内的ACID可以控制,那么节点间的ACID如何控制呢?构建一个可用性和一致性的分布系统成为 ...

  6. GD32电压不足时烧写程序导致程序运行异常的解决方法

    一直使用的GD32F450前段时间遇到这样一个问题,当使用J-Link供电给板子烧写程序之后,程序运行缓慢,就像运行在FLASH高速部分之外一样,但是如果使用外部供电烧写,就不会出现这个问题,而且一旦 ...

  7. 算法与数据结构基础 - 拓扑排序(Topological Sort)

    拓扑排序基础 拓扑排序用于解决有向无环图(DAG,Directed Acyclic Graph)按依赖关系排线性序列问题,直白地说解决这样的问题:有一组数据,其中一些数据依赖其他,问能否按依赖关系排序 ...

  8. Java源码之阻塞队列

    ⑴背景 阻塞队列常用于生产者消费者场景,生产者是向队列里添加元素的线程,消费者是向队列里取出元素的线程.阻塞队列的角色是供生产者存放元素,消费者取出元素的容器. ⑵阻塞队列 阻塞队列是一个支持两个附加 ...

  9. (二十九)c#Winform自定义控件-文本框(二)

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  10. ES6中比较实用的几个特性

    1.Default Parameters(默认参数) in ES6 es6之前,定义默认参数的方法是在一个方法内部定义 var link = function (height, color, url) ...