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 ...
随机推荐
- Java基础集锦——利用Collections.sort方法对list排序
要想对List进行排序,可以让实体对象实现Comparable接口,重写compareTo方法即可实现按某一属性排序,但是这种写法很单一,只能按照固定的一个属性排序,没变法变化.通过下面这种方法,可以 ...
- C# Use Pop3Client to read gmail
host = "pop.gmail.com" user = "xxxxx@gmail.com" password = "xxxx" port ...
- 使用BAT批处理执行sql语句的代码
使用BAT批处理执行sql语句的代码 有时候需要执行一些Sql语句时,不想开企业管理器,或者是发给客户执行但那边又不懂代码,这时就可以用下面方法 1.把待执行Sql保存在一个文件,这里为2011022 ...
- truncate/drop表非常慢,怎么办?用硬链接,极速体验
这个这个,我必须花巨大篇幅,记录下今天清空表记录的英雄壮举,可知道一个drop操作,执行了一下午啊一下午,这是要急出翔的节奏..呵呵,下面开始 我的需求:某表因历史原因,积压了1亿条记录,约占360G ...
- NSURLSession与AFNetworking3.0
下面是用GET方式请求一个页面数据的示例: AFNetworking 2.x NSString *siteUrl = @"http://webinar.ofweek.com/readDemo ...
- winedt设置自动显示行号[latex]
options--preferences--appearance 在show line numbers for modes下面的文本框里添加;Tex 这样新建或者打开tex文件的时候就自动显示行号了( ...
- Android SDK开发包国内下载地址
不知道是因为最近kaihui还是怎么的,打开android sdk官方网站特别的慢,想下载最新版本的platform几乎变成不可能完成的任务,不知道为什么Google不像Apache那样在各国设立镜像 ...
- 用SQL server导出到oracle,查询时提示“表或视图不存在ORA-00942”错误
用SQL server2005的导出工具,将数据导出表到oracle,表名称里看到有这张表了,但查询或删除时都提示“ORA-00942表或者试图不存在”的错误,上网查了一下,是如下原因: “查询或删除 ...
- VisualSFM for Structure from Motion
VisualSFM是Changchang Wu编写的使用 Structure from Motion (SfM)进行3D重建的交互界面,具体内容详见http://homes.cs.washington ...
- oracle 11g 如何创建、修改、删除list-list组合分区
Oracle11g在分区方面做了很大的提高,不但新增了4种复合分区类型,还增加了虚拟列分区.系统分区.INTERVAL分区等功能. 9i开始,Oracle就包括了2种复合分区,RANGE-HASH和R ...