【Codeforces Round #423 (Div. 2) C】String Reconstruction
【Link】:http://codeforces.com/contest/828/problem/C
【Description】
让你猜一个字符串原来是什么;
你知道这个字符串的n个子串;
且知道第i个字符t[i],在k[i]个位置出现过;
且告诉你这k[i]个位置在哪里;
数据不会产生矛盾;
让你输出最终的字符串,输出字典序最小的那个;
【Solution】
对于输入的n个子串;
对于每个位置;
看看那个位置有没有子串之前出现过,没有的话,就放在那个位置;
否则,如果当前这个子串ti的长度比原来在xij那个位置的子串更长;
则也用这个ti代替在xij那个位置的子串;
顺便获取出这个串可能的最长长度maxlen;
然后从1到maxlen枚举
对于第i个位置,如果答案数组s[i]没有值,则ma = i;
(这里的ma,是这一块已经知道字符是什么的块的最末端的位置)
如果有子串s在第i个位置开始;
则从ma开始,到i+leni-1赋值成相应的字符
然后ma = max(ma,i + leni-1);
这样就能避免不必要的重复赋值了;
能跳过已经知道了的字符
如果没有子串s在第i个位置开始;
则,如果s[i]没有值,s[i]=’a’;
上面一开始s[i]没有值的时候,就说明有了间断的地方,则需要重新开始获取最末端了
【NumberOf WA】
0
【Reviw】
能想到这个方法,觉得自己很优秀;
【Code】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int NN = 2e6;
const int N = 1e5;
int n,maxlen = 0;
string t[N+100];
pii open[NN+100];
char s[NN+10];
int main(){
Close();
rep1(i,1,NN) s[i] = '0';
cin >> n;
rep1(i,1,n){
cin >> t[i];
int num;
cin >> num;
rep1(j,1,num){
int p;
cin >> p;
maxlen = max(maxlen,p + (int) t[i].size()-1);
if (open[p].se == 0){
open[p] = mp(i,(int) t[i].size());
}else
if (open[p].se < (int) t[i].size())
open[p] = mp(i,(int) t[i].size());
}
t[i] = ' '+t[i];
}
int ma = 1;
rep1(i,1,maxlen){
if (s[i]=='0') ma = i;
if (open[i].se>0){
rep1(j,ma,i+open[i].se-1){
int k = j-i+1;
s[j] = t[open[i].fi][k];
}
ma = max(ma,i+open[i].se-1);
}
else
if (s[i]=='0')s[i]='a';
}
rep1(i,1,maxlen)
cout << s[i];
cout << endl;
return 0;
}
【Codeforces Round #423 (Div. 2) C】String Reconstruction的更多相关文章
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #422 (Div. 2) D】My pretty girl Noora
[题目链接]:http://codeforces.com/contest/822/problem/D [题意] 有n个人参加选美比赛; 要求把这n个人分成若干个相同大小的组; 每个组内的人数是相同的; ...
- 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)
[题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...
- 【Codeforces Round #422 (Div. 2) B】Crossword solving
[题目链接]:http://codeforces.com/contest/822/problem/B [题意] 让你用s去匹配t,问你最少需要修改s中的多少个字符; 才能在t中匹配到s; [题解] O ...
随机推荐
- iOS Device Types
ios 设备硬件名称对照表 https://support.hockeyapp.net/kb/client-integration-ios-mac-os-x-tvos/ios-device-types ...
- sftp权限
用户: t1 t2 根目录: /home/data/ /home/data/t1/ drwxr-xr-x. 2 t1 t1 4096 Mar 24 17:26 t1 /home/data/t2/ dr ...
- ActiveMQ学习笔记(16)----Message Dispatch高级特性(二)
1. Optimized Acknowledgetment ActiveMQ缺省支持批量确认消息,由于批量确认会提高性能,如果希望在应用程序中禁止经过优化的确认方式,可以采用以下几种方式: 1. 在C ...
- PHP 使用 Swoole - TaskWorker 实现异步操作 Mysql
在一般的 Server 程序中都会有一些耗时的任务,比如:发送邮件.聊天服务器发送广播等.如果我们采用同步阻塞的防水去执行这些任务,那么这肯定会非常的慢. Swoole 的 TaskWorker 进程 ...
- Datazen图表创建和公布
Datazen是被微软收购的移动端全平台的数据展现解决方式.此篇主要介绍怎样创建和公布图表. 如前面介绍,Datazen图表的创建和公布是通过Publisher的应用,它是Windows 8应用 ...
- 【C++探索之旅】第二部分第一课:面向对象初探,string的惊天内幕
内容简单介绍 1.第二部分第一课:面向对象初探.string的惊天内幕 2.第二部分第二课预告:掀起了"类"的盖头来(一) 面向对象初探,string的惊天内幕 上一课<[C ...
- MPI搭建简要教程
具体安装部署,能够參考 http://www.ibm.com/developerworks/cn/linux/l-cn-mpich2/,该教程将的比較具体. 注:不同版本号的 MPICH2对编译器以及 ...
- 1264: [AHOI2006]基因匹配Match(动态规划神题)
1264: [AHOI2006]基因匹配Match 题目:传送门 简要题意: 给出两个序列.每个序列都由n种不同的数字组成,保证每个序列种每种数字都会出现5次(位置不一定一样),也就是序列长度为5*n ...
- struts2 validate验证
转自:https://blog.csdn.net/houpengfei111/article/details/9038233 自定义拦截器 要自定义拦截器需要实现com.opensymphony.xw ...
- ORM中基于对象查询与基于queryset查询
感谢老男孩~ 一步一步走下去 前面是视图函数 后面是表结构models.py from django.shortcuts import render, HttpResponse from djang ...