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 ...
随机推荐
- Codeforces 601D. Acyclic Organic Compounds(四个愿望一次满足)
trie合并的裸题...因为最多只有n个点,所以最多合并n次,复杂度$O(N*26)$. #include<iostream> #include<cstring> #inclu ...
- 51nod求助
求助dalao们,51nod1170实在是不会了,有没有大佬讲一下,有兴趣的可以告诉我,我提供AC代码. using System; using System.Collections.Generic; ...
- [JSOI2008]Blue Mary的战役地图——全网唯一一篇dp题解
全网唯一一篇dp题解 网上貌似全部都是哈希+二分(反正我是大概baidu了翻了翻)(还有人暴力AC了的..) 哈希还是相对于dp还是比较麻烦的. 而且正确性还有可能被卡(当然这个题不会) 而且还容易写 ...
- The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - C 暴力 STL
What Kind of Friends Are You? Time Limit: 1 Second Memory Limit: 65536 KB Japari Park is a larg ...
- Hdu5693 D Game
D Game Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- 线程同步API及它们的属性
头文件:<pthread.h> 编译记得加 -lpthread库 1:互斥锁(mutex) 1.1:互斥锁API 数据类型:pthread_mutex_t // 初始化一个互斥锁 int ...
- SpringBoot(三) :Spring boot 中 Redis 的使用
前言: 这一篇讲的是Spring Boot中Redis的运用,之前没有在项目中用过Redis,所以没有太大的感觉,以后可能需要回头再来仔细看看. 原文出处: 纯洁的微笑 SpringBoot对常用的数 ...
- [吴恩达机器学习笔记]12支持向量机1从逻辑回归到SVM/SVM的损失函数
12.支持向量机 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考资料 斯坦福大学 2014 机器学习教程中文笔记 by 黄海广 12.1 SVM损失函数 从逻辑回归到支持向量机 为了描述 ...
- Java的StringAPI的小练习
//-------------String类-------------- //求两个字符串的最大相同子串 /* 思路: 1.找出较短的那个字符串 2.找出短串的所有子串,使用contains函数判断是 ...
- NOIP 2015 提高组 Day2
期望得分:100+10+60=170 实际得分:100+10+35=145 http://www.cogs.pro/cogs/page/page.php?aid=16 T1 跳石头 时间限制:1 s ...