ex_KMP--Theme Section
题目网址: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110060#problem/B
Description
To get well prepared for the festival, the hosts want to know the maximum possible length of the theme section of each song. Can you help us?
Input
Output
Sample Input
xy
abc
aaa
aaaaba
aaxoaaaaa
Sample Output
0
1
1
2
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
char s[];
int nex[];
int pre[]; void ex_next(int length)
{
///nex[i]: 以第i位置开始的子串与T的前缀的最大长度;
int i,j;
nex[]=length;
for(i=; i<length-&&s[i]==s[i+];i++);///前缀都是同一个字母的时候;
nex[]=i;
int a=;///a为使匹配到最远的地方时的起始匹配地点;
for(int k=;k<length;k++)
{
int p=a+nex[a]-,L=nex[k-a];
if( (k-)+L>=p )
{
int j=(p-k+)>?(p-k+):;
while(k+j<length&&s[k+j]==s[j]) j++;
/// 枚举(p+1,length) 与(p-k+1,length) 区间比较;
nex[k]=j,a=k;
}
else nex[k]=L;
}
} int main()
{
int T,M,n;
scanf("%d",&T);
while(T--)
{
M=;
scanf("%s",s);
int len=strlen(s);
ex_next(len);
for(int i=;i<len;i++)
{
if(nex[i])
{
///此时nex[i]为中间以s[i]开始的子串与前缀匹配的最大长度;
///接下来判断后缀与前缀及中间子串的最大匹配长度;
n=min(min (i,nex[i]),(len-i)/);
for(int j=len-n;j<len;j++)
if(nex[j]==len-j)
{
if(M<nex[j]) M=nex[j];
else break;
}
}
}
printf("%d\n",M);
}
return ;
}
ex_KMP--Theme Section的更多相关文章
- Theme Section(KMP应用 HDU4763)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 4763 Theme Section(KMP水题)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- HDU 4763 Theme Section
题目: It's time for music! A lot of popular musicians are invited to join us in the music festival. Ea ...
- HDU 4763 Theme Section(KMP灵活应用)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu4763 Theme Section【next数组应用】
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 4763 Theme Section (2013长春网络赛1005,KMP)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- (KMP灵活运用 利用Next数组 )Theme Section -- hdu -- 4763
http://acm.hdu.edu.cn/showproblem.php?pid=4763 Theme Section Time Limit: 2000/1000 MS (Java/Others) ...
- hdu4763 Theme Section
地址:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题目: Theme Section Time Limit: 2000/1000 MS (Java/O ...
- HDU4763 Theme Section —— KMP next数组
题目链接:https://vjudge.net/problem/HDU-4763 Theme Section Time Limit: 2000/1000 MS (Java/Others) Mem ...
- HDU4763 Theme Section 【KMP】
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
随机推荐
- Hadoop - 实时查询Drill
1.概述 在现实业务当中,存在这样的业务场景,需要实时去查询HDFS上的相关存储数据,普通的查询(如:Hive查询),时延较高.那么,是否存在时延较小的查询组件.在业界目前较为成熟的有Cloudera ...
- 让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求
原文:http://www.cnblogs.com/dudu/archive/2009/11/10/1600062.html 今天下午17点左右,博客园博客站点出现这样的错误信息: Error Sum ...
- U-boot.lds文件分析
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") ...
- React 根据官方总结的规范
1.语法上,根据生命周期方法执行的顺序编写代码 (1 生命周期方法[getDefaultProps, getInitialState, componentWillMount, componentDid ...
- nc
http://www.oschina.net/translate/nc-command-examples http://nixdoc.net/man-pages/openbsd/man1/nc.1.h ...
- 查看、关闭linux自启动网络服务
1.查看 netstat --tulnp ..master smtp 服务 2.关闭 /etc/init.d/服务 stop 停止 : start 启动 chkconfig 服务 off 关闭 ...
- EPLAN 软件平台中的词“点“大全
1. 中断点(Interruption Point): 在原理图绘制时,如果当前绘图区域的空间不足,需要转到其它页面继续绘制,而这两页之间存在连续的"信息流"时,可以使用& ...
- 最近买了个kindle,为了方便阅读,写了个程序抓取网页内容发送到Kindle
主要觉得往kindle里加书籍太麻烦了,要下载下来,还要通过邮件发送,特别一些网页文字版的书籍没办法放到kindle里,所以想着还不如自己动手丰衣足食,写一个程序直接抓取网页内容,制作成书籍,然后自动 ...
- Unit Of Work--工作单元(二)
回顾 上一篇我们根据工作单元的原理基于ADO.NET进行了简单的实现,但是当项目需求发生变化的时候,比如需要引入ORM框架又要兼容当前ADO.NET实现的方式时,先前的实现就无法满足这个需求了. 话就 ...
- oracle 日期获取
,'YYYY-MM-DD')星期一, to_char(NEXT_DAy(to_date(,'YYYY-MM-DD')星期日 from dual; select to_char(sysdate,'yyy ...