题目大意:告诉你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. Implement Queue by Two Stacks

    As the title described, you should only use two stacks to implement a queue's actions. The queue sho ...

  2. 【bzoj2707】走迷宫

    Portal --> bzoj2707 Solution 首先题目有一个十分明显的暗示..强联通分量..那肯定就是要tarjan一波咯 先看看什么情况下会\(INF\),其实就是题目里面讲的两种 ...

  3. 《剑指offer》— JavaScript(14)链表中倒数第k个结点

    链表中倒数第k个结点 题目描述 输入一个链表,输出该链表中倒数第k个结点. 思路 两个指针,先让第一个指针和第二个指针都指向头结点,然后再让第一个指正走(k-1)步,到达第k个节点: 然后两个指针同时 ...

  4. js中字符串全部替换

    废话不多说,直接发结果 在js中字符串全部替换可以用以下方法: str.replace(/需要替换的字符串/g,"新字符串") 比如: "yyyy-MM-dd-hh-mm ...

  5. 基于epoll封装的事件回调miniserver

    epoll技术前两节已经阐述过了,目前主要做一下封装,很多epoll的服务器都是采用事件回调方式处理, 其实并没有什么复杂的,我慢慢给大家阐述下原理. 在networking.h和networking ...

  6. bzoj 2081 [Poi2010]Beads hash+调和级数

    2081: [Poi2010]Beads Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1003  Solved: 334[Submit][Statu ...

  7. python练习1--用户登入

    python版本为python3.51.要求 1)输入用户名密码 2)认证成功后显示欢迎信息 3)输错三次后锁定 2.需求分析 1)用户信息存储在文件中(login/config/user_login ...

  8. springboot创建maven多模块项目

    SpringBoot创建maven多模块项目 项目结构 该项目名称为springboot-maven-multi,由springboot-maven-multi.user-dao.user-domai ...

  9. Codechef Dynamic Trees and Queries

    Home » Practice(Hard) » Dynamic Trees and Queries Problem Code: ANUDTQSubmit https://www.codechef.co ...

  10. chmod及chown命令详解

    1,chmod 指令名称 : chmod 使用权限 : 所有使用者 使用方式 : chmod [-cfvR] [--help] [--version] mode file... 说明 : Linux/ ...