poj 2334 Simple prefix compression(胡搞)
来源:互联网 发布:jira切换数据库 编辑:程序博客网 时间:2024/06/06 08:24
Simple prefix compression
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 1861 Accepted: 813
Description
Many databases store the data in the character fields (and especially indices) using prefix compression. This technique compresses a sequence of strings A1, ..., AN by the following method: if there are strings Ai = ai,1ai,2...ai,p and Ai + 1 = ai+1,1ai+1,2...ai+1,q
such that for some j ≤ min(p, q) ai,1 = ai+1,1, ai,2 = ai+1,2, ... ai,j = ai+1,j, then the second string is stored as [j]ai+1,j+1ai+1,j+2... ai+1,q, where [j] is a single character with code j.
If j = 0, that is, strings do not have any common prefix, then the second string is prefixed with zero byte, and so the total length actually increases.
Constraints
1 ≤ N ≤ 10000, 1 ≤ length(Ai) ≤ 255.
such that for some j ≤ min(p, q) ai,1 = ai+1,1, ai,2 = ai+1,2, ... ai,j = ai+1,j, then the second string is stored as [j]ai+1,j+1ai+1,j+2... ai+1,q, where [j] is a single character with code j.
If j = 0, that is, strings do not have any common prefix, then the second string is prefixed with zero byte, and so the total length actually increases.
Constraints
1 ≤ N ≤ 10000, 1 ≤ length(Ai) ≤ 255.
Input
First line of input contains integer number N, with following N lines containing strings A1 ... AN
Output
Output must contain a single integer -- minimal total length of compressed strings.
Sample Input
3abcatestatext
Sample Output
11
tips:马德,至今未看懂题意;看着别人的题解慢慢的胡搞;
具体来说每一次都统计与前面一个字符串的前缀数量;然后将长度-前缀数量的长度累加起来;然后胡搞没看懂题
#include<iostream>#include<cstring>#include<string>using namespace std;int n;string last,now; int main(){cin>>n;int ans=0;while(n--){last=now;cin>>now;int sz=0;for(int i=0;i<last.size()&&i<now.size();i++){if(now[i]!=last[i])break;sz++;//统计前缀长度 }ans+=(now.size()-sz+1);//非前缀长度; }cout<<ans-1<<endl; return 0; }
阅读全文
0 0
- poj 2334 Simple prefix compression(胡搞)
- 2334:Simple prefix compression
- poj 2334 Simple prefix compression(模拟/字符串处理)
- #2334:Simple prefix compression--关于string.length()
- Simple prefix compression
- Simple prefix compression 问题
- Simple prefix compression
- Simple prefix compression
- [递归]Simple prefix compression
- A:Simple prefix compression来自百炼2
- 胡搞
- Simple String Compression Functions
- HBase HFile与Prefix Compression内部实现全解
- poj 2001 shortest prefix
- POJ 2001 Shortest Prefix
- Compression
- poj 3444 Wavelet Compression 模拟水题
- POJ 1126 Simple Syntax
- Tensorflow-pb保存与导入
- Jack 服务编译问题 Android 7.0
- TYVJ 4865 天天和树tree || 清北学堂金秋杯大奖赛
- Scrollview如何自适应Listview/GridView
- (2)x210:change the physical meme addr to 30000000 in uboot
- poj 2334 Simple prefix compression(胡搞)
- 欢迎使用CSDN-markdown编辑器
- 线程基本概念
- cocosstudio3.10一些注意事项
- iOS 直播技术文档
- Swift 关于tabbar image渲染的问题
- 031、内部类
- 机器与人类的关系 踏入人工智能的世界
- 函数参数压栈的顺序为从右向左