D Cloud of Hashtags Codeforces Round #401 (Div. 2)
Cloud of Hashtags
【题目链接】Cloud of Hashtags
&题意:
给你一个n,之后给出n个串,这些串的总长度不超过5e5,你要删除最少的单词(并且只能是后缀),使得这些串是按字典序排列的.
&题解:
这也是个水题,当然了,是在你能想到的情况下,然而我还是没想到.
首先你要推出一个结论:最后一行是绝对不可以删的.
你也许会想的这种情况:
#c
#c
#a
如果删了最后一个,那么前2个c就不用删了,但这是错的,因为空字符比a还要小,你如果把a删了,那么你就必须把前面2个c删了,这样才能符合条件.
如果你能推出这个,那就快a了这题了.
之后想到的就是,根据最后一个,向上两两比较,比较完后修改上面的那个,之后继续向上向上两两比较.
最后根据你记录的长度输出答案即可.
&代码:
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
using ll=long long;
const int maxn= 5e5 +9;
int n;
string s[maxn];
int v[maxn];
int main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// freopen("C:\\Users\\Zmy\\Desktop\\in.txt", "r", stdin);
cin>>n;
for(int i=0;i<n;i++){
cin>>s[i];
v[i]=s[i].size();
}
for(int i=n-1;i>0;i--){
string a=s[i],b=s[i-1];
if(a<b){
int p=min(v[i],v[i-1]);
for(int j=0;j<p&&a[j]>=b[j];j++){
v[i-1]=j+1;
}
s[i-1]=s[i-1].substr(0,v[i-1]);
}
}
for(int i=0;i<n;i++){
s[i].resize(v[i]);
cout<<s[i]<<'\n';
}
return 0;
}
D Cloud of Hashtags Codeforces Round #401 (Div. 2)的更多相关文章
- Codeforces Round #401 (Div. 2) 离翻身就差2分钟
Codeforces Round #401 (Div. 2) 很happy,现场榜很happy,完全将昨晚的不悦忘了.终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35 ...
- Codeforces Round #401 (Div. 2) A,B,C,D,E
A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #401 (Div. 2) D Cloud of Hashtags —— 字符串
题目链接:http://codeforces.com/contest/777/problem/D 题解: 题意:给出n行字符串,对其进行字典序剪辑.我自己的想法是正向剪辑的,即先对第一第二个字符串进行 ...
- 【贪心】Codeforces Round #401 (Div. 2) D. Cloud of Hashtags
从后向前枚举字符串,然后从左向右枚举位. 如果该串的某位比之前的串的该位小,那么将之前的那串截断. 如果该串的某位比之前的串的该位大,那么之前那串可以直接保留全长度. 具体看代码. #include& ...
- 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 ...
- Codeforces Round #401 (Div. 2)
和FallDream dalao一起从学长那借了个小号打Div2,他切ABE我做CD,我这里就写下CD题解,剩下的戳这里 AC:All Rank:33 小号Rating:1539+217->17 ...
- C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)
Alyona and Spreadsheet 这就是一道思维的题,谈不上算法什么的,但我当时就是不会,直到别人告诉了我,我才懂了的.唉 为什么总是这么弱呢? [题目链接]Alyona and Spre ...
- Codeforces Round #401 (Div. 2) A B C 水 贪心 dp
A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #401 (Div. 1) C(set+树状数组)
题意: 给出一个序列,给出一个k,要求给出一个划分方案,使得连续区间内不同的数不超过k个,问划分的最少区间个数,输出时将k=1~n的答案都输出 比赛的时候想的有点偏,然后写了个nlog^2n的做法,T ...
随机推荐
- Django:环境搭建
django环境配置 1.安装django pip install django #安装指定版本 pip install -v django==1.8.2 通过python shell查看版本,返回版 ...
- OPTIMIZE TABLE linked list 表优化原理 链表数据结构 空间再利用
小结: 1.加快读写: 2.对于InnoDB表,在一定条件下,通过复制旧表重建: 3.实践中, 3.1.show processlist;查看线程,发现,认为堵塞读请求: 3.2.数据长度空间不变,索 ...
- [development][C] linux 设置线程名称
两个API, 都是linux的. 不是POSIX, 是GNU? 傻傻搞不清楚. 1. pthread_setname_np / pthread_setname_np 2. ptctl 带 PR_GE ...
- Python判断字符串是否为字母或者数字
严格解析:有除了数字或者字母外的符号(空格,分号,etc.)都会Falseisalnum()必须是数字和字母的混合isalpha()不区分大小写 str_1 = "123" str ...
- 不看好运维竖井产品模式,优云打造融合化运维PaaS平台
2018年1月13号中国双态运维用户大会上,优云软件总裁刘东海接受了36Kr记者的专访,期间谈到了新时代下的企业运维模式,新兴技术和传统运维的融合以及优云未来的发展方向等问题.以下为访谈实录: 优云软 ...
- There are 0 datanode(s) running and no node(s) are excluded in this operation.
向hadoop导入文件,报错 .... There are 0 datanode(s) running and no node(s) are excluded in this operation. . ...
- ubuntu14.04下开启ssh服务
1. 安装 sudo apt-get update sudo apt-get install openssh-server 2.开启服务 查看查看ssh服务是否启动 打开"终端窗口" ...
- Intellij IDEA中修改Maven项目的项目名称
1. 原项目名:votesystem-redis 想要重命名成新项目名:votesystem 2. 我们对此项目名进行Rename 3. 再对此项目所在的目录下进行修改 4. 重新打开项目 若 ...
- 前端 CSS 三种引入方式
CSS三种引入方式 行内样式 内接样式 外部样式 链接式 导入式 行内样式 就是在标签加上style属性设置样式 <!DOCTYPE html> <html lang="e ...
- mongodb studio 3t 破解无限使用脚本
@echo off ECHO 重置Studio 3T的使用日期...... FOR /f "tokens=1,2,* " %%i IN ('reg query "HKEY ...