Codeforces Round #423 Div. 2 C-String Reconstruction(思维)
题目大意:告诉你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(思维)的更多相关文章
- 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 ...
- 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 Round #423 (Div. 2)
codeforces 423 A. Restaurant Tables [水题] //注意,一个人选座位的顺序,先去单人桌,没有则去空的双人桌,再没有则去有一个人坐着的双人桌.读清题意. #inclu ...
- 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 ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【贪心】Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A. String Reconstruction
在每个给出的子串的起始位置打个标记,记录的是从这里开始的最长子串. 然后输出的时候就扫,如果遇到开始位置,就从这里开始输出,如果其后被更长的覆盖,就跳转到更长的串进行输出. 如果位置没被覆盖,就输出' ...
- Codeforces Round #192 (Div. 1) C. Graph Reconstruction 随机化
C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/3 ...
- 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 ...
- 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 ...
随机推荐
- 使用Ajax内容签名,减少流量浪费
前端UI界面用Ajax获取数据内容的时候,一般是直接获取内容数据并填充,不管内容有无变化,不管数据量多大,都是直接重新加载数据,例如定时刷新公告等. 今天在浏览器控制台调试的时候,发现动态刷新内容,其 ...
- [USACO09OPEN] 工作调度Work Scheduling (贪心/堆)
[USACO09OPEN] 工作调度Work Scheduling 题意翻译 约翰有太多的工作要做.为了让农场高效运转,他必须靠他的工作赚钱,每项工作花一个单位时间. 他的工作日从0时刻开始,有10^ ...
- js 多个事件的绑定及移除(包括原生写法和 jquery 写法)
需要打开控制台查看效果: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- 2018南京ICPCMediocre String Problem 马拉车
hash+二分求出最长公共前缀 然后马拉车+前缀和计数 #include <cstdio> #include <cstring> #include <queue> ...
- php网摘收藏
1.thinkphp3.2.3开发手册: http://document.thinkphp.cn/manual_3_2.html 2.ThinkPHP3.2.3的函数汇总:http://www.thi ...
- Hibernate学习(5)- session的get与load方法对比
1.共同点:get和load都是根据Id单条查询获取对象 org.hibernate.Session.load(Class<User> theClass, Serializable id) ...
- OpenCV---图像加载与保存
一:获取图像的信息 什么是图像: 结构化存储的数据信息 图像属性: -通道数目 -高与宽 -像素数据 -位图深度 import cv2 as cv def get_image_info(image): ...
- WebApi连接数据库
首先在web.config中加上语句连接语句: <connectionStrings> <add name="conn" connectionString=&qu ...
- 数字配对(bzoj 4514)
Description 有 n 种数字,第 i 种数字是 ai.有 bi 个,权值是 ci. 若两个数字 ai.aj 满足,ai 是 aj 的倍数,且 ai/aj 是一个质数, 那么这两个数字可以配对 ...
- 本地文件夹如何断开svn连接
最近遇到一个问题,svn的项目down失败,一不小心点了删除准备重新上传,发现本地的文件已有svn源信息,提交更新均报再找不到此文件路径. 于是想着删除此文件夹的svn信息,经过一番百度,以下方法测试 ...