【贪心】Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A. String Reconstruction
在每个给出的子串的起始位置打个标记,记录的是从这里开始的最长子串。
然后输出的时候就扫,如果遇到开始位置,就从这里开始输出,如果其后被更长的覆盖,就跳转到更长的串进行输出。
如果位置没被覆盖,就输出'a'。
#include<cstdio>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
string s[100010];
int n,m,p[2000010],len[100010],nn,now;
void print(int x){
for(int i=x,j=0;j<len[p[x]];++i,++j){
if(!p[i] || i==x || len[p[i]]+j<=len[p[x]]){
putchar(s[p[x]][j]);
now=max(now,i);
}
else{
print(i);
break;
}
}
}
int main(){
int x;
scanf("%d",&n);
for(int i=1;i<=n;++i){
cin>>s[i]>>m;
len[i]=s[i].length();
for(int j=1;j<=m;++j){
scanf("%d",&x);
if(len[i]>len[p[x]]){
p[x]=i;
nn=max(nn,x+len[i]-1);
}
}
}
for(int i=1;i<=nn;){
if(p[i]){
print(i);
i=now+1;
}
else{
putchar('a');
++i;
}
}
puts("");
return 0;
}
【贪心】Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A. String Reconstruction的更多相关文章
- 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. 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) E. DNA Evolution 树状数组
E. DNA Evolution 题目连接: http://codeforces.com/contest/828/problem/E Description Everyone knows that D ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 828E) - 分块
Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) D. High Load 构造
D. High Load 题目连接: http://codeforces.com/contest/828/problem/D Description Arkady needs your help ag ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) A,B,C
A.题目链接:http://codeforces.com/contest/828/problem/A 解题思路: 直接暴力模拟 #include<bits/stdc++.h> using ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem A - B
Pronlem A In a small restaurant there are a tables for one person and b tables for two persons. It i ...
随机推荐
- bzoj 3197 DP
这道题我们可以看成给定两个黑白树,可以修改其中一棵树的颜色,问最少修改多少颜色可以使两棵树同构. 首先我们知道在树的同构中树上最长链中点(如果是偶数的话就是中间两个点)是不变的,我们把这个点叫做树的重 ...
- 小程序_RSA加密功能
这是开发的第三个小程序,基于一个物流系统,简化功能开发下单流程.登录的时候,系统是使用RSA进行加解密的. 流程:第一个接口获取到后端传过来的密匙共钥(publicKey),通过公钥使用RSA加密密码 ...
- AndroidStudio获得发布版安全码SHA1
耗了一下午才搞定 在cmd中: 1.打开keytool的目录:即JDK的安装目录 2.输入口令: (E:\tenyears\tenyears\app是keystore文件的目录)
- 二叉查找树、平衡二叉树、红黑树、B-/B+树性能对比
转载:https://blog.csdn.net/z702143700/article/details/49079107 前言:BST.AVL.RBT.B-tree都是动态结构,查找时间基本都在O(l ...
- php快速入门总结
因为本人已经接触了C和C++两年多了,虽然真正用它们的机会很少,但是基本的语法还是相对熟悉的.半年前的课程设计用了PHP,所以当初我也只是现学先用, 学得很粗糙,现在,跟一个同学合作搞一个比赛的项目, ...
- python基础===解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX(转载)
本文转自:解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX 从网上抓了一些字 ...
- barrier 和 preempt_disable() 学习【转】
#define preempt_disable() \ do{ \ inc_preempt_count(); \ barrier(); \ }while(0) 一.这个barrier 在干什么. ...
- hadoop安装 伪分布
伪分布hadoop 安装总结 准备,在配置中hadoop用的9000端口,如果有其它软件用着这个端口,建议更换后再进行下面配置,以避免出现错误.比如php-fpm经常使用9000端口. 一.下载jdk ...
- C#调用Excel报 error CS1969: 找不到编译动态表达式所需的一个或多个类型。是否缺少引用?
转自[http://blog.csdn.net/bodybo/article/details/43191319] 程序需要读取Exel文件,有如下代码段 object oMissing = Syste ...
- 无缝滚动Js
<html> <body> <div style="width: 190px; height: 127px; overflow: hidden; font-si ...