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 ...
随机推荐
- 第7月第12天 opengles background
1. After your app exits its applicationDidEnterBackground: method, it must not make any new OpenGL E ...
- 20165320 2017-2018-2《Java程序设计》课程总结
20165320 2017-2017-2<Java程序设计>课程总结 一.每周作业链接汇总 1.我期待的师生关系 20165320 我期望的师生关系 2.学习基础和C语言基础调查 2016 ...
- Dream------hive on spark
一.Hive on Spark是Hive跑在Spark上,用的是Spark执行引擎,而不是MapReduce,和Hive on Tez的道理一样. 并且用的是$HIVE_HOME/bin/hive,l ...
- CodeSmith的基础模版类(CodeSmith help中的内容)
基础模版类类型描述: Batch OutputFileCodeTemplate 模版通过继承此类能够在生成过程中把他们的输出保存到文件中 ScriptError 在脚本执行中出现一个 ...
- keyspace notification(键空间通知)-待验证
一.需求分析: 设置了生存时间的Key,在过期时能不能有所提示? 如果能对过期Key有个监听,如何对过期Key进行一个回调处理? 如何使用 Redis 来实现定时任务? 二.序言: 本文所说的定时任务 ...
- android 通用 Intent
通用 Intent 本文内容显示详细信息 闹钟 日历 相机 联系人/人员应用 电子邮件 文件存储 本地操作 地图 音乐或视频 新笔记 电话 搜索 设置 发送短信 网络浏览器 使用 Android 调试 ...
- MongoDB学习笔记-1
mongod --dbpath D:\MogonDB3.4.10\db //开启数据库,无端口号mongod --dbpath D:\MogonDB3.4.10\db --port=10086 //开 ...
- zoj 3809 枚举水题 (2014牡丹江网赛 A题)
题目大意:给出一列取样的几个山的高度点,求山峰有几个? Sample Input 291 3 2 4 6 3 2 3 151 2 3 4 5Sample Output 30 # include < ...
- 【Java】 int与char类型间的相互转化
在[Java] 剑指offer(16) 打印1到最大的n位数中遇到了int类型与char类型之间的转换,这里总结一下. (1)int类型转char类型,将数字加一个‘0’,并强制类型转换为char即可 ...
- PowerDesigner的安装
1.下载 2.步骤 3.效果 二:破解 1.参考文档 https://www.7down.com/soft/180716.html 2.说明 主要是一个文件,替换掉文件中的文件即可.