【HDU4691】【后缀数组】Front compression 题解

本文介绍了前缀压缩算法(Front compression),一种delta编码压缩算法,用于记录共同前缀及其长度以减少重复。文章通过实例展示了算法的工作原理,并提供了一道编程题目(HDU4691),要求根据输入的子串计算原始字符串及其压缩后的大小。给出的样例和解题思路解释了如何计算原字符串和压缩后字符串的长度,并提示可以使用后缀数组方法求解,尽管暴力解法在给定数据规模下也可行。
摘要由CSDN通过智能技术生成

Front compression

翻译见后

Description

Front compression is a type of delta encoding compression algorithm whereby common prefixes and their lengths are recorded so that they need not be duplicated. For example:
这里写图片描述
The size of the input is 43 bytes, while the size of the compressed output is 40. Here, every space and newline is also counted as 1 byte.
Given the input, each line of which is a substring of a long string, what are sizes of it and corresponding compressed output?

Input

There are multiple test cases. Process to the End of File.
The first line of each test case is a long string S made up of lowercase letters, whose length doesn’t exceed 100,000. The second line contains a integer 1 ≤ N ≤ 100,000, which is the number of lines in the input. Each of the following N lines contains two integers 0 ≤ A < B ≤ length(S), indicating that that line of the input is substring [A, B) of S.

Output

For each test case, output the sizes of the input and corresponding compressed output.

Sample Input

frcode
2
0 6
0 6
unitedstatesofamerica
3
0 6
0 12
0 21
myxophytamyxopodnabnabbednabbingnabit
6
0 9
9 16
16 19
19 25
25 32
32 37

Sample Output

14 12
42 31
43 40

翻译:

题意:
根据图中的方法压缩输入的字符串,压缩后为可匹配的长度空格与剩余的字符串,输出未压缩字符串的长度与压缩后的长度,空格与提行也算。
这里写图片描述

我们来模拟一个样例:
frcode
2
0 6
0 6
则第一个输入串为frcode,第二个也为frcode,原串为
frcode
frcode
它的压缩后结果为
0 frcode
6
于是它的原长为14,压缩后为12。

那么我们发现原长十分好算,即每次的长度相加即可,而压缩后的长度就可以有后缀数组来解决(这个题数据水,暴力也能过)。最后注意一下精度就AC~(≧▽≦)/~啦啦啦。

附代码:


                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值