【贪心】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 ...
随机推荐
- react组件之间的几种通信情况
组件之间的几种通信情况 父组件向子组件通信 子组件向父组件通信 跨级组件通信 没有嵌套关系组件之间的通信 1,父组件向子组件传递 React数据流动是单向的,父组件向子组件通信也是最常见的;父组件通过 ...
- 【bug】vue-cli 3.0报错的解决办法
先上bug图片 bug说明:初装vue_cli3.0写了个组件,运行错误,显示如图, 代码提示:[Vue warn]: You are using the runtime-only build of ...
- Linux简介——(一)
1. 常见操作系统 - 服务端操作系统 : linux.unix.windows server - 单机操作系统 : windows(dos .ucdos.win95.win98.win2000.xp ...
- [New learn]SDWebImage框架的基本使用
代码:https://github.com/xufeng79x/SDWebImage 1.简介 SDWebImage是一个第三方框架,它能够帮助我们有效管理应用图片下载,沙盒保存和内存保存的任务.通过 ...
- IntelliJ IDEA centos安装
安装的时候注意: 不要装一个插件否则无法启动!!!
- 今天开始学模式识别与机器学习(PRML),章节5.1,Neural Networks神经网络-前向网络。
今天开始学模式识别与机器学习Pattern Recognition and Machine Learning (PRML),章节5.1,Neural Networks神经网络-前向网络. 话说上一次写 ...
- linux系统使用过程遇到的bug
使用windows与ubuntu双系统,重装windows系统后需要修复ubuntu grub reference ubuntu系统中挂载的windows硬盘点不开 需要重新挂载 reference ...
- 经验分享:如何系统学习 Web 前端技术?
这篇文章主要是面向小白用户的,如果你有些基础,当然也建议你看看,尤其是最后一个主题,或许你能得到一些启发.本文的观点,纯属个人自以为是的想法,不是真理,仅供参考. 抛开具体技术细节,先主要谈谈程序员如 ...
- ngCordova安装配置使用教程
ngCordova是什么 ngCordova是在Cordova Api基础上封装的一系列开源的AngularJs服务和扩展,让开发者可以方便的在HybridApp开发中调用设备能力,即可以在Angul ...
- 【转载】RecyclerView源码解析
原文地址:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/0307/4032.html 概述 之前面试的时候经常有人问是否用过Re ...