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

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

  1. #include <iostream>
  2. #include <cstring>
  3. #include <queue>
  4. #include <vector>
  5. #include <cstdio>
  6. #include <map>
  7. #include <string>
  8. #include <vector>
  9. using namespace std;
  10. const int M = 2e6 + 10;
  11. const int N = 1e5 + 10;
  12. int pos;
  13. struct TnT {
  14. int sta, ed , num;
  15. TnT() {}
  16. TnT(int sta , int ed , int num):sta(sta), ed(ed), num(num) {}
  17. bool operator <(const TnT &a) const {
  18. return ed - pos > a.ed - pos;
  19. }
  20. };
  21. priority_queue<TnT>q;
  22. vector<int>vc[M];
  23. string s[N];
  24. int main() {
  25. int n, k, pp;
  26. scanf("%d" , &n);
  27. int Max = 1;
  28. for(int i = 1 ; i <= n ; i++) {
  29. cin >> s[i];
  30. cin >> k;
  31. int len = s[i].size();
  32. for(int j = 0 ; j < k ; j++) {
  33. cin >> pp;
  34. Max = max(Max , pp + len - 1);
  35. vc[pp - 1].push_back(i);
  36. }
  37. }
  38. for(pos = 0 ; pos < Max ; pos++) {
  39. int len = vc[pos].size();
  40. for(int i = 0 ; i < len ; i++) {
  41. int L = s[vc[pos][i]].size();
  42. q.push(TnT(pos , pos + L - 1 , vc[pos][i]));
  43. }
  44. if(q.empty()) cout << 'a';
  45. else {
  46. cout << s[q.top().num][pos - q.top().sta];
  47. while(!q.empty()) {
  48. if(q.top().ed == pos) q.pop();
  49. else break;
  50. }
  51. }
  52. }
  53. cout << endl;
  54. return 0;
  55. }

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】删除 main.storyboard 的问题

    一直没用 main.storyboard, 后来索性把它删了,结果还出了问题: Terminating app due to uncaught exception 'NSInvalidArgument ...

  2. WPF界面的异步后台加载

    private void Init()         {                     BackgroundWorker worker = new BackgroundWorker(); ...

  3. 【原创】TextCNN原理详解(一)

    ​ 最近一直在研究textCNN算法,准备写一个系列,每周更新一篇,大致包括以下内容: TextCNN基本原理和优劣势 TextCNN代码详解(附Github链接) TextCNN模型实践迭代经验总结 ...

  4. 富文本编辑器TinyMCE的使用(React Vue)

    富文本编辑器TinyMCE的使用(React Vue) 一,需求与介绍 1.1,需求 编辑新闻等富有个性化的文本 1.2,介绍 TinyMCE是一款易用.且功能强大的所见即所得的富文本编辑器. Tin ...

  5. 【精选】Markdown 语法汇总

    博客园也能Markdown?美滋滋,Markdown真的是好用QAQ. 本文档按照Markdown各种常用语法类别,以文字描述+演示的方式来展现markdown语法的使用.Markdown 的目标是实 ...

  6. Python3源代码编译安装

    Python3源代码编译安装 安装必要工具 yum-utils ,它的功能是管理repository及扩展包的工具 (主要是针对repository) $ sudo yum install yum-u ...

  7. HTML/CSS:div居中和div内部元素垂直居中(1)

    div居中 div水平和垂直居中,text-align和vertical-align不起作用,因为标签div没有这两个属性,所以再css中设置这两个值不能居中的效果 1. div水平居中:设置marg ...

  8. .Net Core2.1 秒杀项目一步步实现CI/CD(Centos7.2)系列一:k8s高可用集群搭建总结以及部署API到k8s

    前言:本系列博客又更新了,是博主研究很长时间,亲自动手实践过后的心得,k8s集群是购买了5台阿里云服务器部署的,这个集群差不多搞了一周时间,关于k8s的知识点,我也是刚入门,这方面的知识建议参考博客园 ...

  9. 身体质量指数BMI

    Solution: 方法一:"Python语言程序设计"(中国大学MOOC平台)的答案 分析:对比两种指标,将共性(相同的区间)和异性(不同的区间)细分.这样两种指标的判断条件(不 ...

  10. [Spring cloud 一步步实现广告系统] 20. 系统运行测试

    系统运行 经过长时间的编码实现,我们的主体模块已经大致完成,因为之前我们都是零散的对各个微服务自行测试,接下来,我们需要将所有的服务模块进行联调测试,Let's do it. 清除测试数据&测 ...