Codeforces777D Cloud of Hashtags 2017-05-04 18:06 67人阅读 评论(0) 收藏
2 seconds
256 megabytes
standard input
standard output
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more
 comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the
 beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of
 characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible.
 If there are several optimal solutions, he is fine with any of them.
The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) —
 the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
Print the resulting hashtags in any of the optimal solutions.
3
#book
#bigtown
#big
#b
#big
#big
3
#book
#cool
#cold
#book
#co
#cold
4
#car
#cart
#art
#at
#
#
#art
#at
3
#apple
#apple
#fruit
#apple
#apple
#fruit
Word a1, a2, ..., am of
 length m is lexicographically not greater than word b1, b2, ..., bk of
 length k, if one of two conditions hold:
- at first position i, such that ai ≠ bi,
the character ai goes
earlier in the alphabet than character bi,
i.e. a has smaller character than bin
the first position where they differ; - if there is no such position i and m ≤ k,
i.e. the first word is a prefix of the second or two words are equal. 
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why
 in the third sample we can't keep first two hashtags unchanged and shorten the other two.
——————————————————————————————————————
题意:给出几个字符串,要求删除尾部尽可能少的字母,是的单词按字典序上升(可以相等)
思路:从最后一个开始处理,每个单词尽可能少删除,可以开一个数组记录每个单词最多可以取到什么位置
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std; vector<char>s[500005];
char x[500005];
int ans[500005];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
s[i].clear(); for(int i=0; i<n; i++)
{
scanf("%s",&x);
int k=strlen(x);
for(int j=0; j<k; j++)
s[i].push_back(x[j]);
}
ans[n-1]=s[n-1].size()-1;
for(int i=n-2; i>=0; i--)
{
int k=s[i].size();
for(int j=0; j<k; j++)
{
if((j==ans[i+1]||j==k-1)&&s[i][j]==s[i+1][j])
{
ans[i]=min(k-1,ans[i+1]);
break;
}
if(s[i][j]<s[i+1][j])
{
ans[i]=k-1;
break;
}
else if(s[i][j]>s[i+1][j])
{
ans[i]=j-1;
break;
}
}
} for(int i=0;i<n;i++)
{
for(int j=0;j<=ans[i];j++)
cout<<s[i][j];
cout<<endl;
} }
return 0;
}
Codeforces777D Cloud of Hashtags 2017-05-04 18:06 67人阅读 评论(0) 收藏的更多相关文章
- {A} + {B}                                                       分类:            HDU             2015-07-11 18:06    6人阅读    评论(0)    收藏
		
{A} + {B} Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
 - POJ3045 Cow Acrobats                                                                                            2017-05-11 18:06             31人阅读              评论(0)              收藏
		
Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4998 Accepted: 1892 Desc ...
 - HDU6023 Automatic Judge                                                                                            2017-05-07 18:30             73人阅读              评论(0)              收藏
		
Automatic Judge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
 - Rebuild my Ubuntu                                                    分类:            ubuntu             shell             2014-11-08 18:23    193人阅读    评论(0)    收藏
		
全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...
 - Doubles                                                       分类:            POJ             2015-06-12 18:24    11人阅读    评论(0)    收藏
		
Doubles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19954 Accepted: 11536 Descrip ...
 - OpenCV与QT联合编译                                                    分类:            Eye_Detection             ZedBoard             OpenCV             shell             ubuntu             2014-11-08 18:54    143人阅读    评论(0)    收藏
		
问题1:首先参考rainysky的博客,发现qmake时发生找不到目录,文件的错误,又找不到 qmake.conf 文件的写法.所以开始按照网上的程序修改 XXX.pro 文件. 问题2:使用QT C ...
 - 移植QT到ZedBoard(制作运行库镜像) 交叉编译                                                    分类:            ubuntu             shell             ZedBoard             OpenCV             2014-11-08 18:49    219人阅读    评论(0)    收藏
		
制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...
 - highgui.h备查                                                    分类:            C/C++             OpenCV             2014-11-08 18:11    292人阅读    评论(0)    收藏
		
/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...
 - OC基础:数组.字典.集                                                    分类:            ios学习 OC             2015-06-18 18:58    47人阅读    评论(0)    收藏
		
==============NSArray(不可变数组)=========== NSArray,继承自NSObject 用来管理(储存)一些有序的对象,不可变数组. 创建一个空数组 NSArray ...
 
随机推荐
- Null value was assigned to a property of primitive type setter of"原因及解决方法
			
在action请求数据的过程中报出"Null value was assigned to a property of primitive type setter of"错误,搜索之 ...
 - r.js打包
			
久闻r.js的大名,但实际没有用它做过任何东西.今天用它时,发现网上许多教程都不对.研究一下,把我的实际经验分享给大家. 例子1 先是HTML页面 <!DOCTYPE html> < ...
 - vmadm命令
			
VMADM(1M)VMADM(1M) 名称 vmadm - 管理SmartOS虚拟机 概要 / usr / vm / sbin / vmadm <command> [-d] [-v] [特 ...
 - xpath的层级与逻辑定位
			
xpath的层级与逻辑定位: 之前我们是通过class和id,name,如果我们所需要的元素没有class,id,name这样的元素,怎么定位呢 1.在不使用xpath情况下:元素没有属性值得时候怎么 ...
 - Princess Principal(思维题)
			
Princess Principal https://www.nowcoder.com/acm/contest/201/J 题目描述 阿尔比恩王国(the Albion Kingdom)潜伏着一群代号 ...
 - 【校招面试 之 C/C++】第28题 C++ 内存泄漏的检查
			
1.memwatch的使用 (1)首先去官网上下载源码: http://www.linkdata.se/sourcecode/memwatch/ 解压得到memwatch.c以及memwatch.h两 ...
 - JSP标准标签库JSTL
			
1.什么是JSTL? JSP标准标签库(JSP Standard Tag Library) 2.JSTL标准标签库中的常用标签 JSTL是JSP页面的标签库,实质上是一段Java代码.我们常用的是它的 ...
 - AspectJ的XML方式完成AOP的开发之AOP的通知类型
			
1. 前置通知 * 在目标类的方法执行之前执行. * 配置文件信息:<aop:after method="before" pointcut-ref="myPoint ...
 - win7系统administrator用户提示没有管理员权限,造装驱动安装错误,软件无法使用
			
警告1909.无法创建快捷方式 最近使用windows 7 32位安装软件,好多都失败.出现以上类似错误. 解决方法:在系统盘(C:)右键属性“安全”选项卡--“编辑”,添加“Everyone”设置为 ...
 - 5.Javascript 原型链之原型对象、实例和构造函数三者之间的关系
			
前言:用了这么久js,对于它的原型链一直有种模糊的不确切感,很不爽,隧解析之. 本文主要解决的问题有以下三个: (1)constructor 和 prototype 以及实例之间啥关系? (2)pro ...