题目大意:告诉你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. BZOJ2716:[Violet 3]天使玩偶——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2716 样例输入 2 31 12 32 1 21 3 32 4 2 样例输出 1 2 ———————— ...

  2. HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧)

    HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧) 题意分析 题目大意:一个h*w的公告牌,要在其上贴公告. 输入的是1*wi的w值,这些是公告的尺寸. 贴公告 ...

  3. Linux基础-正则表达式整理---------------grep、sed、awk

    目录:    Ⅰ:正则表达式    Ⅱ:作业 Ⅰ:正则表达式 正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描述一类事物的规则. 在lin ...

  4. 认识Java标识符

    标识符定义 认识Java标识符 在编程语言中,标识符就是程序员自己规定的具有特定含义的词,比如类名称,属性名称,变量名等. 问:标识符是神马? 答:标识符就是用于给 Java 程序中变量.类.方法等命 ...

  5. Codeforces 543.B Destroying Roads

    B. Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. portal商品展示功能逻辑

    看下接口: 返回值: 门户商品搜索功能的实现: 根据分类id进行搜索,根据关键词进行搜索,并按照一定的顺序排序 业务逻辑: 1.查询分类是否存在. 2.如果分类存在,则递归分类,展示父类商品,子类商品 ...

  7. Qt ------ stylesheet 样式

    1.所有的窗口组件都可以用 setStyleSheet() 设置样式 2.使用样式,显示效果可以不受平台影响,比如保证window 7 和 linux 显示效果是一样的 QVariant 如果 sty ...

  8. C语言 两个小知识点

    strlen 函数原型 extern unsigned int strlen(char *s); 在Visual C++ 6.0中,原型为size_t strlen(const char *strin ...

  9. [吴恩达机器学习笔记]12支持向量机4核函数和标记点kernels and landmark

    12.支持向量机 觉得有用的话,欢迎一起讨论相互学习~Follow Me 12.4 核函数与标记点- Kernels and landmarks 问题引入 如果你有以下的训练集,然后想去拟合其能够分开 ...

  10. 使用$http.post()提交数据后台接收不到

    传参方式是request payload,参数格式是json,而并非用的是form传参,所以在后台用接收form数据的方式接收参数就接收不到了. POST表单请求提交时,使用的Content-Type ...