Compress Words
直接套 KMP 即可(那为什么打 cf 的时候没有想到...),求出后一个单词(word)的前缀数组,然后从前面已得的字符串的末尾 - word. length () 开始查询利用前缀数组进行优化即可
代码:
// Created by CAD on 2019/8/12.
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int, int>;
using piii=pair<pair<int, int>, int>;
using ll=long long;
const int maxn=1e6+5;
int nxt[maxn];
void get_next(string s)
{
int i=0,j=-1;nxt[0]=-1;
int n=s.length();
while(i<n)
{
if(j==-1||s[i]==s[j])
nxt[++i]=++j;
else j=nxt[j];
}
}
string ans,word;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
for(int i=1;i<=n;++i)
{
cin>>word;
int wlen=word.length();
int alen=ans.length();
get_next(word);
int match=0;
for(int j=max(alen-wlen,0);j<alen;++j)
{
while(match>0&&ans[j]!=word[match]) match=nxt[match];
if(ans[j]==word[match]) match++;
}
ans+=word.substr(match);
}
cout<<ans<<endl;
return 0;
}
Compress Words的更多相关文章
- 压缩和解压文件:tar gzip bzip2 compress(转)
tar[必要参数][选择参数][文件] 压缩:tar -czvf filename.tar.gz targetfile解压:tar -zxvf filename.tar.gz参数说明: -c 建立新的 ...
- apache.commons.compress 压缩,解压
最近在一个前辈的指引下,开始研究apache.commons.都是网上找的,而且不会中文乱码,而且还可以在压缩包里面加一层文件夹 package my.test; import java.io.Buf ...
- Linux下的压缩和解压缩命令——compress/uncompress
compress命令 compress命令使用"Lempress-Ziv"编码压缩数据文件.compress是个历史悠久的压缩程序,文件经它压缩后,其名称后面会多出".Z ...
- AIX 文件 打包 与 压缩 tar gzip compress 的使用
今天在Aix用tar -cvf 备份,打成tar包,占有硬盘空间过大,没有压缩比, 尝试使用tar -zcvf linux系统下可以用-z 命令 (z 用gzip来压缩/解压缩文件,加上该选项后可以 ...
- impdp导入报错ORA-14460: only one COMPRESS or NOCOMPRESS clause may be specified
迁移环境 源:Solaris 10 + Oracle 11.2.0.3 目标:Solaris 10 + Oracle 11.2.0.1 导出命令: expdp user/pwd directory=j ...
- [CareerCup] 1.5 Compress String 压缩字符串
1.5 Implement a method to perform basic string compression using the counts of repeated characters. ...
- Compress a Folder/Directory via Perl5
Compress a Folder/Directory via Perl5 tested in Windows, Mac OS X, Ubuntu16.04 #!/usr/bin/perl #压缩指定 ...
- PLSQL_批量压缩表Table Compress(案例)
2015-04-01 Created By BaoXinjian
- compress 表设置及索引设置
-- 查看表大小 from user_segments where segment_name='TableName'; -- 查看表大小 size_m -- 2000.6796875 2211.695 ...
- Compress、tar、gzip、zcat、bzip2、bzcat、打包解压命令行
讲解内容: Linux环境中,压缩文件案的扩展名大多是*.tar,*.tar.gz,*.tgz,*.gz,*.Z,*.bz2. *.z compress程序亚索的文件: *.g ...
随机推荐
- 【pytorch】学习笔记(三)-激励函数
[pytorch]学习笔记-激励函数 学习自:莫烦python 什么是激励函数 一句话概括 Activation: 就是让神经网络可以描述非线性问题的步骤, 是神经网络变得更强大 1.激活函数是用来加 ...
- Feign声明式服务调用
Feign是一种声明式.模板化的HTTP客户端(仅在Application Client中使用).声明式调用是指,就像调用本地方法一样调用远程方法,无需感知操作远程http请求. Spring Clo ...
- Python和其他编程语言
Python和其他编程语言 一.Python介绍 Python的创始人为吉多·范罗苏姆(Guido van Rossum),如下图,少数几个不秃头的语言创始人.1989年的圣诞节期间,Guido为了打 ...
- oracle查看执行计划以及使用场景
文档结构: oracle执行计划使用场景 环境: Centos 6.10 Oracle 18.3.0.0.0 c 11g默认启动了自动统计信息收集的任务,默认运行时间是周一到周五晚上10点和周6,周天 ...
- js中的奇闻异事
- django自带登录认证与登录自动跳转
# 导入django自带模块 from django.contrib.auth import authenticate, login, logout # 使用authenticate进行认证,使用lo ...
- replace函数更换表中字段的域名
网站域名更换后,数据库很多链接都是存的绝对路径,这时候需要修改表里字段的路径,使用replace函数更改域名 update 表名 set 字段名 =replace(字段名 ,'旧域名','新域名') ...
- jq上滑加载更多
html 结构 <div id="main"> <ul class="order-list" id="list_box"& ...
- java中的Enum在@RestController(@ResponseBody) 注解下返回的表现
参考文档 枚举 public enum CouponType { PLATFORM("平台优惠券"), NEWCOMER("新人专享优惠券"), INVITE( ...
- Linux--Shell 编程-bash,命令替换,if分支嵌套,运算,输入输出
SHELL 编程 shell 是一个命令解释器,侦听用户指令.启动这些指令.将结果返回给用户(交互式的shell) shell 也是一种简单的程序设计语言.利用它可以编写一些系统脚本. ...