hdu4763 Theme Section
地址:http://acm.hdu.edu.cn/showproblem.php?pid=4763
题目:
Theme Section
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3491 Accepted Submission(s): 1623
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?
xy
abc
aaa
aaaaba
aaxoaaaaa
0
1
1
2
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define PI acos((double)-1)
#define E exp(double(1))
const int K=1e6+;
int nt[K];
char a[K]; //参数为模板串和next数组
//字符串均从下标0开始
void kmp_next(char *T,int *nt)
{
nt[]=;
for(int i=,j=,m=strlen(T);i<m;i++)
{
while(j&&T[i]!=T[j])j=nt[j-];
if(T[i]==T[j])j++;
nt[i]=j;
}
} int main(void)
{
int t;cin>>t;
while(t--)
{
scanf("%s",a);
kmp_next(a,nt);
int len=strlen(a);
int ans=nt[len-],ff=;
while(ans)
{
for(int i=ans;i<=len-ans&&ff;i++)
if(nt[i]==ans)
ff=;
if(!ff) break;
ans=nt[ans-];
}
printf("%d\n",ans);
} return ;
}
hdu4763 Theme Section的更多相关文章
- HDU4763 Theme Section —— KMP next数组
题目链接:https://vjudge.net/problem/HDU-4763 Theme Section Time Limit: 2000/1000 MS (Java/Others) Mem ...
- hdu4763 Theme Section【next数组应用】
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU4763 Theme Section 【KMP】
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- HDU4763 - Theme Section(KMP)
题目描述 给定一个字符串S,要求你找到一个最长的子串,它既是S的前缀,也是S的后缀,并且在S的内部也出现过(非端点) 题解 CF原题不解释....http://codeforces.com/probl ...
- HDU-4763 Theme Section KMP
题意:求最长的子串E,使母串满足EAEBE的形式,A.B可以任意,并且不能重叠. 题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4763 思 ...
- 【kmp算法】hdu4763 Theme Section
kmp中next数组的含义是:next[i]表示对于s[0]~s[i-1]这个前缀而言,最大相等的前后缀的长度是多少.规定next[0]=-1. 迭代for(int i=next[i];i!=-1;i ...
- 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 ...
随机推荐
- python定义函数时的默认返回值
python定义函数时,一般都会有指定返回值,如果没有显式指定返回值,那么python就会默认返回值为None, 即隐式返回语句: return None 执行如下代码 def now(): prin ...
- winform 递归循环阻止机构
private void GetTree() { DataTable dt = new DataTable(); var sql = @" select OUID,ParentOUID,OU ...
- javascript new Date()函数在不同浏览器上返回不同的值
今天是2015年3月16日,在IE 6 上new Date()返回给后台server的字符串格式为 "Mon Mar 16 00:00:00 UTC 0800 2015",而在f ...
- 解决项目导入dubbo依赖项目报红叉问题
1.maven+ssm项目导入dubbo依赖 项目报错如下 2.出错原因在于dubbo依赖低版本的spring和低版本netty,准备通过maven的依赖管理将依赖传递过来的低版本的spring和ne ...
- Android Studio添加assets文件夹
Step #1:调出项目结构管理区域 View->Tool Windows->Project Step #2:结构管理区域选择“Project” Step #3:新建"asset ...
- TCL电视直播软件
升级你的电视系统我的型号46寸 V7300 3D,具体的升级程序在"技术宅"里有下载 找个格式化过的U盘把你的程序拷贝进去,插在电视上,电视会自动升级 当你成功安装V8-0MT32 ...
- IT资料常用网址汇总
菜鸟联盟: http://www.runoob.com/ w3c school :https://www.w3cschool.cn/ http://www.w3school.com.cn/w3c/in ...
- 在R语言中封装类读写sql操作工具类
1.mysql_helper.R # 使用RMySQL操作数据库 # 载入DBI和RMySQL包 library(DBI) library(RMySQL) mysql_con <- functi ...
- EIT: where is it now and what lies ahead?
EIT: where is it now and what lies ahead? Electrical impedance tomography (EIT) is an emerging clini ...
- 前端开发 - HTML
1.index2.head标签相关内容3.常用标签一4.常用标签二 table5.常用标签二 form6.标签分类 1.index <!--声明文档的类型 标记该文档为HTML5的文件--> ...