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 ...
随机推荐
- Woody的Python学习笔记3
Python运算符 Python逻辑运算符 and布尔与-假设x为false.x and y返回false,否则它返回y的计算值. or 布尔或-假设x是true,它返回true.否则它返回y的计算值 ...
- Hadoop1.2.1 的 “Hello world!”
下图是大概步骤: 下面是详细步骤,但我的代码跟上面有点不一样,但都是一个道理: 第一个程序测试 wordcount 先创建目录 hadoop fs -mkdir /wc hadoop fs -mkdi ...
- Influxdb时序数据库阅读笔记
时序数据库 2017年2月Facebook开源了beringei时序数据库:到了4月基于PostgreSQL打造的时序数据库TimeScaleDB也开源了,而早在2016年7月,百度云在其天工物联网平 ...
- 用DX9画三角形,三个顶点要求
用DX9画三角形,三个顶点的顺序有要求吗下面是全部代码,在 InitVB 函数中被注释掉的数组是我写的,没注释掉的是书上的代码,经过试验我的坐标不能显示出图形,而书上的坐标可以,这是为什么? #i ...
- 【BZOJ1050】[HAOI2006]旅行comf 并查集
[BZOJ1050][HAOI2006]旅行comf Description 给你一个无向图,N(N<=500)个顶点, M(M<=5000)条边,每条边有一个权值Vi(Vi<300 ...
- SignalR 循序渐进(四) Hub的生命周期以及IoC
有阵子没更新这个系列了,最近太忙了.本篇带来的是Hub的生命周期以及IoC. 首先,Hub的生命周期,我们用一个Demo来看看: public class TestHub : Hub { public ...
- closure--- 闭包与并行运算
闭包有效的减少了函数所需定义的参数数目.这对于并行运算来说有重要的意义.在并行运算的环境下,我们可以让每台电脑负责一个函数,然后将一台电脑的输出和下一台电脑的输入串联起来.最终,我们像流水线一样工 ...
- 如何使用 libtorch 实现 LeNet 网络?
如何使用 libtorch 实现 LeNet 网络? LeNet 网络论文地址: http://yann.lecun.com/exdb/publis/pdf/lecun-01a.pdf
- python发送邮件的2种方式
发送邮件的2种方式1.匿名发送 smtpObj = smtplib.SMTP(host, port) smtpObj.sendmail(from_addr, to_addrs, message.as_ ...
- windows server 2008 r2 IIS 6 元数据库与IIS 6 配置的兼容性 解决方案
1 菜单-管理工具-服务器管理 2 添加角色服务 3 选中 IIS6 管理兼容性 4 安装完成 5 在IIS上新建一个相应端口的网站 6重新加载项目,OK