Theme Section

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 271    Accepted Submission(s): 121

Problem Description
It's time for music! A lot of popular musicians are invited to join us in the music festival. Each of them will play one of their representative songs. To make the programs more interesting and challenging, the hosts are going to add some constraints to the rhythm of the songs, i.e., each song is required to have a 'theme section'. The theme section shall be played at the beginning, the middle, and the end of each song. More specifically, given a theme section E, the song will be in the format of 'EAEBE', where section A and section B could have arbitrary number of notes. Note that there are 26 types of notes, denoted by lower case letters 'a' - 'z'.

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
The integer N in the first line denotes the total number of songs in the festival. Each of the following N lines consists of one string, indicating the notes of the i-th (1 <= i <= N) song. The length of the string will not exceed 10^6.
 
Output
There will be N lines in the output, where the i-th line denotes the maximum possible length of the theme section of the i-th song.
 
Sample Input
5
xy
abc
aaa
aaaaba
aaxoaaaaa
 
Sample Output
0
0
1
1
2
 
Source
 
Recommend
liuyiding
 

就是要中间找一段最长的和,和开头和结尾一样。

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)的更多相关文章

  1. HDU 4768 Flyer (2013长春网络赛1010题,二分)

    Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  2. HDU 4764 Stone (2013长春网络赛,水博弈)

    Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  3. 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 ...

  4. HDU 4759 Poker Shuffle(2013长春网络赛1001题)

    Poker Shuffle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  5. HDU 4816 Bathysphere (2013长春现场赛D题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...

  6. HDU 4747 Mex (2013杭州网络赛1010题,线段树)

    Mex Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

  7. HDU 4733 G(x) (2013成都网络赛,递推)

    G(x) Time Limit: 2000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  8. hdu 4763 Theme Section(KMP水题)

    Theme Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  9. HDU 4763 Theme Section

    题目: It's time for music! A lot of popular musicians are invited to join us in the music festival. Ea ...

随机推荐

  1. 2016-2017-2 20155309 南皓芯java第六周学习总结

    教材内容详解 这一次主要学习的是第十章与第十一章的内容.主要讲述了串流,字符处理和线程以及并行API. 输入输出 串流:Java中的数据有来源(source)和目的地(destination),衔接两 ...

  2. python中的__new__、__init__和__del__

    __new__.__init__.__del__三个方法用于实例的创建和销毁,在使用python的类中,我们最常用的是__init__方法,通常称为构造方法,__new__方法几乎不会使用,这篇文章是 ...

  3. 第12月第15天 mysqlx boost reswift

    1. INSTALL PLUGIN mysqlx SONAME 'mysqlx.so' https://yq.aliyun.com/articles/38288 2. boost boost::sha ...

  4. Metasploit输出重定向到文件

    Metasploit是我们经常会使用到的神器,但是运行exploit/run无法保存输出信息,查看不是很方便. 现在可以使用spool来保存输出信息: Metasploit Framework Con ...

  5. C型USB能阻止危险充电器通过USB传播恶意软件

    C型USB能阻止危险充电器通过USB传播恶意软件 C型USB设备(USB Type-C)的新型身份验证协议可以保护用户免受潜在的充电器损坏的风险,这种新型的USB还能减少被恶意软件的风险.基于密码的认 ...

  6. 纠正几个NANDFLASH很容易犯的错误【转】

    转自:https://blog.csdn.net/pengrui18/article/details/32337297 今天在看别人如何根据物理地址计算NANDFLASH的列地址(column add ...

  7. NEERC Southern Subregional 2012

    NEERC Southern Subregional 2012 Problem B. Chess Championship 题目描述:有两个序列\(a, b\),两个序列都有\(n\)个数,并且这\( ...

  8. vs 调试不进入断点

    背景 或许当时环境不知发了什么神经,就是不调试了.竟然还有这种简单错误. 解决方案---配置管理器---选择debug模式

  9. 洛谷P3383线性筛素数

    传送门 代码中体现在那个 $ break $ $ prime $ 数组 中的素数是递增的,当 $ i $ 能整除 $ prime[j ] $ ,那么 $ iprime[j+1] $ 这个合数肯定被 $ ...

  10. SecureCRT中常用linux命令 -《转载》

    常用命令: 一.ls 只列出文件名 (相当于dir,dir也可以使用) -A:列出所有文件,包含隐藏文 件. -l:列表形式,包含文件的绝大部分属性. -R:递归显示. --help:此命令的帮助. ...