D. Cloud of Hashtags
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.

Input
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.

Output
Print the resulting hashtags in any of the optimal solutions.

Examples
input
3
#book
#bigtown
#big
output
#b
#big
#big
input
3
#book
#cool
#cold
output
#book
#co
#cold
input
4
#car
#cart
#art
#at
output
#
#
#art
#at
input
3
#apple
#apple
#fruit
output
#apple
#apple
#fruit
Note
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 b in 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.

题意:给出N接着是N行字符串,可以删除每个字符串的尽量短后缀,使得从上往下的字符串符合字典序相等或上升,最后一行字符串不可做任何删除。输出处理后的字符串。

思路:从最后一行开始往上遍历,删掉上一行比当前行字典序大的部分即可,毫无技巧,纯粹暴力模拟

代码

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<vector>
using namespace std;
const int maxn=500005;
vector<string>str;
int main()
{int N;scanf("%d",&N);for(int i=0; i<N; i++){string temp;cin>>temp;str.push_back(temp);}
//    for(int i=0; i<N; i++)
//        printf("%d***\n",(int)str[i].size());for(int i=N-2; i>=0; i--){if(str[i]>str[i+1])//使满足str[i]<=str[i+1];{string flag;int j=0;while(j<min((int)str[i].size(),(int)str[i+1].size())&&str[i][j]<=str[i+1][j])j++;while(j<(int)str[i].size()){str[i][j]='\0';j++;}}}for(int i=0; i<N; i++){for(int j=0; j<(int)str[i].size()&&str[i][j]!='\0'; j++)cout<<str[i][j];printf("\n");}return 0;
}

Codeforces Round #401 (Div. 2) D. Cloud of Hashtags(暴力)相关推荐

  1. Codeforces Round #401 (Div. 2) D. Cloud of Hashtags

    题目链接:D. Cloud of Hashtags 题意: 给你n个字符串,让你删后缀,使得这些字符串按字典序排列,要求是删除的后缀最少 题解: 由于n比较大,我们可以将全部的字符串存在一个数组里面, ...

  2. Codeforces Round #401 (Div. 2) D. Cloud of Hashtags(字符串 + 逆向思维)

    D. Cloud of Hashtags 题意: 给你n个字符串,不能改变顺序,每个字符串可以选择从结尾删除连续的一段,使这n个字符串满足字典序从小到大的顺序.要求:删除的字符串尽量少. 题解: 最重 ...

  3. Codeforces Round #401 (Div. 2) D Cloud of Hashtags —— 串

    题目链接:http://codeforces.com/contest/777/problem/D 题解: 题意:给出n行字符串,对其进行字典序剪辑.我自己的想法是正向剪辑的,即先对第一第二个字符串进行 ...

  4. Codeforces Round #743 (Div. 2) E. Paint 区间dp + 暴力

    传送门 文章目录 题意: 思路: 题意: 给你一个有nnn个像素的图像,每个像素都有一个颜色aia_iai​,保证每种颜色的图像不会超过202020个.你现在每次可以选择一个颜色,并选择一段连续的像素 ...

  5. Codeforces Round #271 (Div. 2) C. Captain Marmot (暴力枚举+正方形判定)

    题目链接:Codeforces Round #271 (Div. 2) C. Captain Marmot 题意:给4行数据,每行2个点.(x,y).(a,b).意思是(x,y)绕(a,b)逆时针旋转 ...

  6. Codeforces Round #401 (Div. 2) C Alyona and Spreadsheet —— 打表

    题目链接:http://codeforces.com/contest/777/problem/C C. Alyona and Spreadsheet time limit per test 1 sec ...

  7. Codeforces Round #401 (Div. 2) E. Hanoi Factory 栈

    E. Hanoi Factory 链接: http://codeforces.com/contest/777/problem/E 题解: 排序b从小到大,在b相同排序a从小到大,使其满足如果i-1不能 ...

  8. Codeforces Round #401 (Div. 1) C(set+树状数组)

    题意: 给出一个序列,给出一个k,要求给出一个划分方案,使得连续区间内不同的数不超过k个,问划分的最少区间个数,输出时将k=1~n的答案都输出 比赛的时候想的有点偏,然后写了个nlog^2n的做法,T ...

  9. Codeforces Round #253 (Div. 1) A. Borya and Hanabi 暴力

    A. Borya and Hanabi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/442/p ...

最新文章

  1. 安装虚拟机及Linux常用操作命令
  2. 2008 R2 AD通过组策略针对用户进行限制QQ等软件的运行
  3. hive无法执行带where语句的SQL
  4. OpenCV学习笔记(四十六)——FAST特征点检测features2D OpenCV学习笔记(四十七)——VideoWriter生成视频流highgui OpenCV学习笔记(四十八)——PCA算
  5. 2019年第十届蓝桥杯 - 省赛 - C/C++大学C组 - B. 矩形切割
  6. 你的灯亮着么阅读笔记3
  7. 吴恩达深度学习(一)-第三周:Planar data classification with one hidden layer
  8. springboot读取src下文件_java(包括springboot)读取resources下文件方式
  9. 使用jQuery Mobile快速开发手机站点
  10. 镜像配置见证机失败解决方案
  11. Excel如何利用条件格式找出数据区域中最大的几项
  12. 给spring容器注册组件
  13. Java异常处理之------Java方法中throws Exception使用案例!什么情况下使用throws Exception?...
  14. Java基础(一):简介和基础数据类型
  15. DOM元素节点属性outerHTML和innerHTML
  16. 自己DIY一个pinephone——debian与主线linux在红米2(msm8916)上的移植 (二)
  17. 气压曲线软件 android,GPS气压海拔测量
  18. 一起学JAVA之【基础篇】4种默认线程池介绍
  19. 微信小程序里面的标签和html标签的对比、微信小程序基础之常用控件
  20. python函数结构_Python代码结构:函数

热门文章

  1. Packet(信息包)
  2. Ubuntu 微信QQ企业微信不能输入中文
  3. oracle空的显示成减号,qdrzq
  4. 位,字节,字,字长的区别是什么?
  5. T3备份提示原先格式化该文件时所用扇区大小为512
  6. Python开源指南
  7. 【PC工具】Samsung Magician三星固态硬盘优化维护工具升级,固态硬盘选型
  8. 微信小程序开发之大转盘 抽奖
  9. 可能是最全的人工智能入门书单(附PDF链接)
  10. ai不同形状的拼版插件_Illustrator(AI)自动拼版脚本 V1.5下载(编组对象的复制位移)...