HDU 4763 Theme Section (2013长春网络赛1005,KMP)
Theme Section
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 271 Accepted Submission(s): 121
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
就是要中间找一段最长的和,和开头和结尾一样。
KMP就解决了。
有点暴力。
先next[n]一直标记下。
然后循环找next,更新答案
/* ***********************************************
Author :kuangbin
Created Time :2013-9-29 18:18:34
File Name :E:\2013ACM练习\2013网络赛\2013长春网络赛\1005.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; void kmp_pre(char x[],int m,int next[])
{
int i,j;
j = next[] = -;
i = ;
while(i < m)
{
while( - != j && x[i] != x[j] )j = next[j];
next[++i] = ++j;
}
}
char str[];
int next[];
bool f[];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",str);
int n = strlen(str);
kmp_pre(str,n,next);
memset(f,false,sizeof(f));
int tmp = n;
while(tmp > )
{
if(n >= *tmp)f[tmp] = true;
tmp = next[tmp];
}
int ans = ;
for(int i = n-;i > ;i--)
{
tmp = i;
while(tmp > )
{
if(f[tmp] && i >= *tmp && n >= i+tmp)
{
ans = max(ans,tmp);
break;
}
tmp = next[tmp];
}
}
printf("%d\n",ans);
}
return ;
}
HDU 4763 Theme Section (2013长春网络赛1005,KMP)的更多相关文章
- HDU 4768 Flyer (2013长春网络赛1010题,二分)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4764 Stone (2013长春网络赛,水博弈)
Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 4759 Poker Shuffle(2013长春网络赛1001题)
Poker Shuffle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 4816 Bathysphere (2013长春现场赛D题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...
- HDU 4747 Mex (2013杭州网络赛1010题,线段树)
Mex Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...
- HDU 4733 G(x) (2013成都网络赛,递推)
G(x) Time Limit: 2000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- 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 ...
随机推荐
- Myeclipse/STS 首次在本地部署配置一个Spring MVC 项目 (十二)
1. 在本地新创建一个文件夹 ,做为项目工作空间; 2. 用 Myeclipse 或 STS 进入该文件夹,该文件夹就成为项目的工作空间: 3. 就要进 窗口-首选项,配置: 环境默认编码: 1> ...
- HTML5+CSS把footer固定在底部
在刚开始给网页写footer的时候,我们会碰到一个让人烦躁的问题:当页面内容太少时,footer显示在了页面中间,这是我们不希望出现的,我们希望它能够永远呆在底部,不管网页的内容是多还是少.下面的代码 ...
- 原生JS获取元素的位置与尺寸
1.内高度.内宽度: 内边距 + 内容框 element.clientWidth element.clientHeight 2.外高度,外宽度: 边框 + 内边距 + 内容框 element.offs ...
- Windows中用“ls”命令
解决办法是: 在C:\Windows\System32目录下新建文本文档,文件内容为: @echo off dir 另存为“ls.bat” 类型为所有文件,编码ANSI 可使用dir 或者ls都可以 ...
- (mysql)触发器、事件、事务、函数
1.事务操作原理:事务开启之后Start transaction,所有的操作都会临时保存到事务日志.只有在得到commit才会关闭,否则清空:2.设置回滚点: savepoint 回滚点名字: 回到 ...
- (转)js函数前加分号和感叹号是什么意思?有什么用?
转载地址:https://www.cnblogs.com/mq0036/p/4605255.html 一般看JQuery插件里的写法是这样的 (function($) { //... })(jQuer ...
- js中call与apply用法
call和apply,它们的作用都是将函数绑定到另外一个对象上去运行 两者的格式和参数定义: call( thisArg [,arg1,arg2,… ] ); // 参数列表,arg1,arg2,.. ...
- VSCode配置简单的vue项目
VSCode配置简单的vue项目 https://www.cnblogs.com/wnxyz8023/p/9989447.html 由于最近要使用的项目框架为前后端分离的,采用的是vue.js+web ...
- jQuery项目赋予Router
给你的jQuery项目赋予Router技能吧 现在你不会React/Vue都不好意思说自己是前端,不过我相信很多前端项目还是基于jquery类库的传统模式的,假如你有追求的态度使用过require ...
- 【LOJ】#6434. 「PKUSC2018」主斗地
题解 什么,我这题竟然快到了LOJ rk1???? 搜起来有点麻烦,不过感觉还是比斗地主好下手(至今没敢写斗地主 首先是暴力搜牌型,最多\(3^{16}\)(什么判解还要复杂度怂成一团)的样子?? 然 ...