【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 ...
随机推荐
- hiho 171周 - 水题,并查集
题目链接 题目描述: 输入4 alice 2 alice@hihocoder.com alice@gmail.com bob 1 bob@qq.com alicebest 2 alice@gmail. ...
- 通过curl获取网页访问时间
curl -w %{time_namelookup}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download}&quo ...
- ActiveMQ学习笔记(7)----ActiveMQ支持的传输协议
1. 连接到ActiveMQ Connector: Active提供的,用来实现连接通讯的功能,包括:client-to-broker,broker-to-broker.ActiveMQ允许客户端使用 ...
- 对称平方数(to_string函数,stoi函数真香)
题目描述 打印所有不超过n(n<256)的,其平方具有对称性质的数.如11*11=121. 输入描述: 无 输出描述: 每行一个数,表示对称平方数. 示例1 输入 复制 无 输出 复制 无解题思 ...
- eclipse界面更改为黑色
效果如下: 更改很简单,该两个配置就行了,如下图: 1.在window中打开Preferences,然后跟下图一样配置就行了.
- 【转载】spring-boot 项目跳转到JSP页面
原路径:https://blog.csdn.net/qq_36820717/article/details/80008225 1.新建spring-boot项目 目录结构如下 2.新建TestCon ...
- pandas 4 处理缺失数据nan
from __future__ import print_function import pandas as pd import numpy as np np.random.seed(1) dates ...
- python list set dict的简单应用示例
list.count(x):返回指定元素x在列表中出现的次数 set(list):将list类型变量转换为set类型,去除重复值 dick:保存键值对 x=[1,2,2,3,3] s1=set(x) ...
- ajax动态添加复选框
function getLands() { $.ajax({ url:"httpserver.do?doPost&userQygs="+$("#userQygs& ...
- 在AutoLyout中动态获得cell的高度 和 autoLyout中的小随笔
autoLyout中动态获得cell的高度和autoLyout小总结 一.在autoLyout中通过动态的方式来获取cell 的方式呢? 1. 在布局时候要有对于cell中contentV ...