题目大意:告诉你n个字符串以及这些字符串在字符串s中出现的位置(x1,x2.....xn),要求在满足上述条件的情况下,求出字典序最小的字符串s。

解题思路:主要问题是,如果直接模拟是会超时的,比如vvvvvvvvvv 3 1 2 3这样就有大量重复(因为题目说了这些字符串位置不会相互矛盾,所以已经有了字符的地方可以不用管了),每次都重复了len-1的长度,如果这段字符串长度为1e6那很容易就超时了。所以这里添加一个pre记录上一次字符串的末尾位置(因为题目说了给出的位置时递增的),每次比较一下开始位置xi和pre+1的大小取较大的为起始的字符添加点。特意画了张丑图:

代码:

 #include<stdio.h>
#include<cstring>
const int N=2e6+; char tmp[N];
char s[N];
int idx[N]; int max(int a,int b){
return a>b?a:b;
} int main(){
memset(s,'#',sizeof(s));
int n,mlen=-;
scanf("%d",&n);
int num=;
for(int i=;i<=n;i++){
int m,pre=-;//pre记录上一次字符串的末尾位置
scanf("%s %d",tmp,&m);
int len=strlen(tmp)-;
while(m--){
int pos,x;
scanf("%d",&x);
mlen=max(mlen,x+len);
pos=max(pre+,x);
for(int j=pos;j<=x+len;j++){
s[j]=tmp[j-pos];
num++;
}
//存储上一次末尾位置
pre=x+len;
}
}
for(int i=;i<=mlen;i++){
if(s[i]=='#')
s[i]='a';
}
s[mlen+]='\0';
printf("%s\n",s+);
}

Codeforces Round #423 Div. 2 C-String Reconstruction(思维)的更多相关文章

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

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

  3. Codeforces Round #423 (Div. 2)

    codeforces 423 A. Restaurant Tables [水题] //注意,一个人选座位的顺序,先去单人桌,没有则去空的双人桌,再没有则去有一个人坐着的双人桌.读清题意. #inclu ...

  4. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C 并查集

    C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  5. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

  6. 【贪心】Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A. String Reconstruction

    在每个给出的子串的起始位置打个标记,记录的是从这里开始的最长子串. 然后输出的时候就扫,如果遇到开始位置,就从这里开始输出,如果其后被更长的覆盖,就跳转到更长的串进行输出. 如果位置没被覆盖,就输出' ...

  7. Codeforces Round #192 (Div. 1) C. Graph Reconstruction 随机化

    C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/3 ...

  8. Codeforces Round #402 (Div. 2) D. String Game

    D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

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

随机推荐

  1. POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)

    POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...

  2. Linux之进程通信20160720

    好久没更新了,今天主要说一下Linux的进程通信,后续Linux方面的更新应该会变缓,因为最近在看Java和安卓方面的知识,后续会根据学习成果不断分享更新Java和安卓的方面的知识~ Linux进程通 ...

  3. 简单shell 编程

    简单shell编程  by  dreamboy #!/bin/bash while true do echo clear echo echo " 系统维护菜单 " echo &qu ...

  4. 阿里云 centos7 tomcat 启动巨慢的解决方法(几分钟)

    方法一: 通过修改Tomcat启动文件-Djava.security.egd=file:/dev/urandom 通过修改JRE中的java.security文件securerandom.source ...

  5. ubuntu系统安装与卸载软件常用命令

    一.unbuntu下的软件安装方式 1.deb包的安装方式 deb是debian系Linux的包管理方式,ubuntu是属于debian系的Linux发行版,所以默认支持这种软件安装方式,当下载到一个 ...

  6. openstack身份认证与API请求流程

    一.概况 1. 请求认证token时,需发送的认证信息包括: 2. 如果认证成功,会获得认证token 3. 在发送的API请求中将认证token填入X-Auth-Token字段.可以一直使用这个认证 ...

  7. jquery validate ajax 验证重复的2种方法

    转载自:http://blog.51yip.com/jsjquery/1484.html jquery validate 经过这种多年的改良,已经很完善了.它能满足80%的验证需要,如果validat ...

  8. React读取Excel——js-xlsx 插件的使用

    介绍 SheetJS js-xlsx 是一款能够读写多种格式表格的插件,浏览器支持良好,并且能在多个语言平台上使用,目前在 github 上有 12602 个 star, 刚好项目中遇到了前端解析 e ...

  9. bzoj 2453: 维护队列

    2453: 维护队列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1079  Solved: 503[Submit][Status][Discuss ...

  10. unZip/Zip的安装

    1.apt-get安装: apt-get install zip 2.yum安装: yum install -y unzip zip