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 ...
随机推荐
- OC中实现锁
熟悉多线程开发的同学对锁肯定不陌生,但是OC中如何实现锁呢?给大家科普一下. 首先构建一个测试用的类,假想它是我们的一个共享资源,method1与method2是互斥的,代码如下: @implemen ...
- CSS font系列
font-family font-family: Verdana,Helvetica,Arial,"Microsoft YaHei",sans-serif; font-family ...
- python3操作数据库 借助pycharm快速连接并操作mysql数据库
1.https://blog.csdn.net/qiushi_1990/article/details/78041299
- linux磁盘空间查看inode
服务器一般是要求长期连续运行的,自动执行任务生成的各种文件及日志,可能使空间占满,从而造成业务故障,所以要定时清理. 一般来说,Linux空间占满有如两种情况: 1.空间被占满了 用df -k 可以看 ...
- 修改MySQL的时区,涉及参数time_zone
原地址:http://blog.csdn.net/mchdba/article/details/9763521 首先需要查看mysql的当前时区,用time_zone参数 mysql> show ...
- android 8.0变更
Android 8.0 行为变更 Android 8.0 除了提供诸多新特性和功能外,还对系统和 API 行为做出了各种变更.本文重点介绍您应该了解并在开发应用时加以考虑的一些主要变更. 其中大部分变 ...
- Android SO文件的兼容和适配
开发Android应用时,有时候Java层的编码不能满足实现需求,就需要到C/C++实现后生成SO文件,再用System.loadLibrary()加载进行调用,这里成为JNI层的实现.常见的场景如: ...
- Java中static关键字概述
例如一个学生类中,我们需要统计下学生类中学生对象的数量,此时数量要定义为静态变量: 示例代码: package com.java1995; public class Student { int id= ...
- Java封装概述
1.封装概述 private public 2.实现封装 例子: package com.java1995; public class Student { private String name; ...
- tomcat错误信息解决方案【严重:StandardServer.await: create[8005]】
错误信息: 严重: StandardServer.await: create[8005]: java.net.BindException: Address already in use: JVM ...