【GDKOI2013选拔】大LCP
来源:互联网 发布:访客网络加密 编辑:程序博客网 时间:2024/05/18 00:28
题目
LCP就是传说中的最长公共前缀,至于为什么要加上一个大字,那是因为…你会知道的。
首先,求LCP就要有字符串。既然那么需要它们,那就给出n个字符串好了。
于是你需要回答询问大LCP,询问给出一个k,你需要求出前k个字符串中两两的LCP最大值是多少,这就是传说中的大LCP。
分析
考虑离线操作,
用
建一棵trie,
依次把输入的字符放入trie,
当做到i时,
#include <cmath>#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <queue>const int maxlongint=2147483647;using namespace std;struct wordtree{ int fz[27];}tree[2000005];char s[1000000];int f[100003],n,m,tot,ans;int main(){ scanf("%d%d",&n,&m); int i,j,k,l,x,y,mx; tot=1; for(i=1;i<=n;i++) { scanf("%s\n",s); x=1; mx=strlen(s); for(j=0;j<=mx-1;j++) { if(tree[x].fz[s[j]-97]) x=tree[x].fz[s[j]-97]; else break; } for(k=j;k<=mx-1;k++) { tree[x].fz[s[k]-97]=++tot; x=tot; } mx=j; f[i]=max(f[i-1],mx); } for(i=1;i<=m;i++) { scanf("%d",&k); printf("%d\n",f[k]); }}
1 0
- 【GDKOI2013选拔】大LCP
- 【GDKOI2013选拔】大LCP
- [jzoj3126]【GDKOI2013选拔】大LCP(字典树解LCP)
- JZOJ 3126. 大LCP
- GDKOI2013 DAY2T4
- LCP
- LCP
- Trie(字典树):大LCP
- JZOJ3126 大LCP(GDKOI 2013)
- 05年中大4+2选拔前四天总结
- 利用后缀数组 前缀 LCP最长公共前缀求第K大的子串
- LCP概念
- LCP概念
- LCP Array
- 志愿者选拔
- 选拔总结
- 选拔忧虑
- 选拔wp
- spring-boot笔记
- [ASP.NET MVC 大牛之路]02 - C#高级知识点概要(1) - 委托和事件
- PAT 1015. Reversible Primes (20)(d进制转化,质数判定(注意等于号))
- Coursera机器学习 week2 assignment
- 微软面试100题目系列---找出字符串中第一个只出现一次的字符
- 【GDKOI2013选拔】大LCP
- Maven 和Eclipse构建web项目(7)
- Photoshop文字特效——霓虹弯管效果的文字
- [ASP.NET MVC 大牛之路]03 - C#高级知识点概要(2) - 线程和并发
- 局域网断网攻击
- 适用的字符串hash函数
- (OK) New location of last_kmsg on Android 6.0 and above: /sys/fs/pstore/console-ramoops
- [ASP.NET MVC 大牛之路]01 - 开篇
- 【Java集合源码剖析】ArrayList源码剖析