在每个给出的子串的起始位置打个标记,记录的是从这里开始的最长子串。

然后输出的时候就扫,如果遇到开始位置,就从这里开始输出,如果其后被更长的覆盖,就跳转到更长的串进行输出。

如果位置没被覆盖,就输出'a'。

#include<cstdio>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
string s[100010];
int n,m,p[2000010],len[100010],nn,now;
void print(int x){
for(int i=x,j=0;j<len[p[x]];++i,++j){
if(!p[i] || i==x || len[p[i]]+j<=len[p[x]]){
putchar(s[p[x]][j]);
now=max(now,i);
}
else{
print(i);
break;
}
}
}
int main(){
int x;
scanf("%d",&n);
for(int i=1;i<=n;++i){
cin>>s[i]>>m;
len[i]=s[i].length();
for(int j=1;j<=m;++j){
scanf("%d",&x);
if(len[i]>len[p[x]]){
p[x]=i;
nn=max(nn,x+len[i]-1);
}
}
}
for(int i=1;i<=nn;){
if(p[i]){
print(i);
i=now+1;
}
else{
putchar('a');
++i;
}
}
puts("");
return 0;
}

【贪心】Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A. String Reconstruction的更多相关文章

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

  2. Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)

    Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A.String Reconstruction B. High Load C ...

  3. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution 树状数组

    E. DNA Evolution 题目连接: http://codeforces.com/contest/828/problem/E Description Everyone knows that D ...

  4. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 828E) - 分块

    Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A ...

  5. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心

    Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...

  6. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) D. High Load 构造

    D. High Load 题目连接: http://codeforces.com/contest/828/problem/D Description Arkady needs your help ag ...

  7. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) A,B,C

    A.题目链接:http://codeforces.com/contest/828/problem/A 解题思路: 直接暴力模拟 #include<bits/stdc++.h> using ...

  8. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集

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

  9. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem A - B

    Pronlem A In a small restaurant there are a tables for one person and b tables for two persons. It i ...

随机推荐

  1. nodejs入门教程之http的get和request简介及应用

    nodejs入门教程之http的get和request简介及应用 前言 上一篇文章,我介绍了nodejs的几个常用的模块及简单的案例,今天我们再来重点看一下nodejs的http模块,关于http模块 ...

  2. python进行机器学习(三)之模型选择与构建

    Scikit-Learn库已经实现了所有基本机器学习的算法,可以直接调用里面库进行模型构建. 一.逻辑回归 大多数情况下被用来解决分类问题(二元分类),但多类的分类(所谓的一对多方法)也适用.这个算法 ...

  3. python mysql插入数据遇到的错误

    1.数据插入的时候报错:not enough arguments for format string,大概意思就是说没有足够的参数格式化字符串. 我的数据库插入方法是这样的 def add_data( ...

  4. Python-生成器/你不知道的点

    1.什么是生成器 通过列表生成式,我们可以直接创建一个列表.但是,受到内存限制,列表容量肯定是有限的.而且,创建一个包含100万个元素的列表,不仅占用很大的存储空间,如果我们仅仅需要访问前面几个元素, ...

  5. Network——物理层-练习题与解答

    1. 无线电天线通常在其直径等于无线电波的波长的情况下工作效果最好.合理的天线直径的范围是从1厘米到5米.问所覆盖的频率范围是怎样的? 解答: λf = c , c=3x108 (m/s) 对于λ=1 ...

  6. 从设计图到CSS:rem+viewport+媒体查询+Sass

    根据UI图对移动端的h5页面做样式重构,是前端工程师的本职工作,看似简单,不过想做好却并不容易.下面总结一下其中要点. rem rem是一种相对长度单位,参考的基准是<html>标签定义的 ...

  7. leetcode 121 122 123 . Best Time to Buy and Sell Stock

    121题目描述: 解题:记录浏览过的天中最低的价格,并不断更新可能的最大收益,只允许买卖一次的动态规划思想. class Solution { public: int maxProfit(vector ...

  8. shell 中的<,<<,>,>>

    相信熟悉linux的童鞋不会对这四个符合陌生,shell脚本的文件流有时候真的挺容易搞晕人的,下面我们一起了解一下吧 参考链接:http://www.cnblogs.com/chengmo/archi ...

  9. 《逐梦旅程 WINDOWS游戏编程之从零开始》笔记1——创建窗口&GDI

    第1章 创建窗口 步骤: 窗口类的设计 窗口类的注册 窗口的正式创建 窗口的显示与更新 消息循环体系 窗口过程函数处理消息 1. 设计:使用WNDCLASSEX结构体,这里注意的是C++中的结构体中的 ...

  10. JQuery 实现 锚点跳转

    $('.nav-jump').click(function() { $('html,body').animate( { scrollTop:$($.attr(this, 'href')).offset ...