【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 ...
随机推荐
- Mysql表引擎的切换
转换MYSQL表的引擎 1.方法一:Alter table 将1个表的引擎修改为另一个引擎最简单的方法是使用Alter table语句. 下面的语句将myTable的引擎修改为InnoDB mysql ...
- 接口测试工具篇--jmeter
jmeter的安装及使用在这里不进行讲解了,网上有很多资料 下面开始讲解如何使用jmeter做http接口测试 在jmeter中添加一个http请求,添加方式:测试计划上邮件添加线程组,线程组上邮件选 ...
- IPv6理论知识详解
1. IPv6地址表示 IPv6地址可以表示为128位由0.1组成的字符串,为了便于计算机理解,将128位的二进制字符串表示为32位的十六进制字符串,为了便于理解,人们将其划分为8组,组与组之间用 : ...
- JAVA调用接口
HttpUrlconnection部分 //发送JSON字符串 如果成功则返回成功标识. public static String doJsonPost(String urlPath, String ...
- django-数据库的查询集
1.curd(增删改查) 对于数据库,作为一名开发人员并不会感到陌生,那么数据库中的查询集是怎么一回事呢? 2.数据库的查询集 查询集这个概念存在django框架中,存在于ORM(object rel ...
- UVA 12003 Array Transformer
Array Transformer Time Limit: 5000ms Memory Limit: 131072KB This problem will be judged on UVA. Orig ...
- zjnu(1181)——石子合并
这道题算是最简单的区间dp了..非常久之前写的,搞懂原理了就1A. 传送门:problem_id=1181">http://acm.zjnu.edu.cn/CLanguage/show ...
- hdu_2795,线段树,单点更新
#include<iostream> #include<cstdio> #include<cstring> #define lson l,m,rt<<1 ...
- Windows10+VS2013+caffe+Python2.7+CUDA8.0 部署配置
所需环境工具: 1. Windows 10 2. VS2013 3. Windows版本的caffe工具包,地址:https://github.com/Microsoft/caffe 4. Anaco ...
- Hadoop的目录结构