codeforces 828 C. String Reconstruction(思维+优先队列)
题目链接: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(思维+优先队列)的更多相关文章
- CodeForces - 827A:String Reconstruction (基础并查集)
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
- Educational Codeforces Round 94 (Rated for Div. 2) String Similarity、RPG Protagonist、Binary String Reconstruction、Zigzags 思维
题目链接:String Similarity 题意: 首先题目定义了两个串的相似(串的构成是0.1),如果两个串存在对于一个下标k,它们的值一样,那么这两个串就相似 然后题目给你一个长度为2n-1的串 ...
- 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 ...
- Codeforces - 828C String Reconstruction —— 并查集find()函数
题目链接:http://codeforces.com/contest/828/problem/C C. String Reconstruction time limit per test 2 seco ...
- Codeforces C - String Reconstruction
C - String Reconstruction 方法一:把确定的点的父亲节点设为下一个点,这样访问过的点的根节点都是没访问过的点. 代码: #include<bits/stdc++.h> ...
- CodeForces - 828C String Reconstruction 并查集(next跳)
String Reconstruction Ivan had string s consisting of small English letters. However, his friend Jul ...
- Codeforces828 C. String Reconstruction
C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- CF1400-C. Binary String Reconstruction
CF1400-C. Binary String Reconstruction 题意: 对于一个二进制字符串\(s\),以及一个给定的\(x\),你可以通过一下操作来得到字符串\(w\): 对于字符串\ ...
- [CodeForces]String Reconstruction
http://codeforces.com/contest/828/problem/C 并查集的神奇应用. #include<bits/stdc++.h> using namespace ...
随机推荐
- 【iOS】no identity found Command /usr/bin/codesign failed with exit code 1
今天遇到了这个问题,详情如下图: 后来发现是自己脑子短路了……只添加了 Provisioning Profiles, 而忘记添加 Certificates, 就是下面的两个:
- Mysql架构简要
1. MySql 最上层是一些客户端和连接服务,包含本地sock通信和大多数基于客户端/服务端工具实现的类似于tcp/ip的通信. 主要完成一些类似于连接处理.授权认证.及相关的安全方案.在该层上引入 ...
- 后端开发实践系列之二——领域驱动设计(DDD)编码实践
Martin Fowler在<企业应用架构模式>一书中写道: I found this(business logic) a curious term because there are f ...
- Java学习多线程第一天
内容介绍 Thread 线程创建 线程池 线程状态图 1 多线程 1.1 多线程介绍 学习多线程之前,我们先要了解几个关于多线程有关的概念. 进程:进程指正在运行的程序.确切的来说,当一个程序 ...
- 自定义FutureTask实现
FutureTask FutureTask是Future的实现,用来异步任务的获取结果,可以启动和取消异步任务,查询异步任务是否计算结束以及获取最终的异步任务的结果.通过get()方法来获取异步任务的 ...
- hadoop hdfs 分布式存储
1.克隆前的工作 1.配置好网络nat 需要设置静态ip并能通过主机上网 ssh 和 rsync 是必须下载的 2.yum install vim wget rsync ssh 并配 ...
- 带你剖析WebGis的世界奥秘----点和线的世界
前言 昨天写了好久的博文我没保存,今天在来想继续写居然没了,气死人啊这种情况你们见到过没,所以今天重新写,我还是切换到了HTML格式的书写上.废话不多说了,我们现在就进入主题,上周我仔细研究了WebG ...
- php opcodes(vld)翻译教程
一.php opcodes的由来(如果你只想知道如何解php opcodes就直接跳过这步) 1.PHP内核-Zend引擎的详解:https://www.php.cn/php-weizijiaoche ...
- AutoResetEvent控制线程用法
本文主要来自一道面试题,由于之前对AutoResetEvent的用户很模糊(即使已经使用过了).面试题题目很简洁:两个线程交替打印0~100的奇偶数.你可以先动手试试,我主要是尝试在一个方法里面完成这 ...
- 11.源码分析---SOFARPC数据透传是实现的?
先把栗子放上,让大家方便测试用: Service端 public static void main(String[] args) { ServerConfig serverConfig = new S ...