Theme Section HDU - 4763(些许暴力)
题意:
求出最长公共前后缀 不能重叠 而且 这个前后缀 在串的中间也要出现一次
解析:
再明确一次next数组的意思:完全匹配的最长前后缀长度
求一遍next 然后暴力枚举就好了
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 1e6+, INF = 0x7fffffff;
int nex[maxn]; void get_next(char *s)
{
int len = strlen(s);
int j = , k = -;
nex[] = -;
while(j < len)
{
if(k == - || s[j] == s[k])
nex[++j] = ++k;
else
k = nex[k];
}
} int kmp(char *s, char *t, int len1, int len2) //串1 串2 串1的长度 串2的长度
{
int i, j = ;
if(len1 == && len2 == )
{
if(s[] == t[])
return true;
else
return false;
}
for(int i=; i<len1; i++)
{
while(j > && s[i] != t[j])
j = nex[j];
if(s[i] == t[j])
j++;
if(j == len2)
return true;
}
} char s[maxn];
char s2[maxn];
int main()
{
int T;
rd(T);
while(T--)
{
rs(s);
get_next(s);
int len = strlen(s);
if(!nex[len]){
cout<< "" <<endl;
}
else
{
int tmp = nex[len];
while(tmp)
{
if(tmp* > len) //如果当前长度大于三倍 那么就用次长来匹配
{
tmp = nex[tmp];
continue;
}
for(int i=; i<tmp; i++) //暴力取出那段子串
s2[i] = s[i];
if(kmp(s+tmp, s2, len - *tmp, tmp))
{
cout<< tmp <<endl;
break;
}
tmp = nex[tmp];
}
}
} return ;
}
Theme Section HDU - 4763(些许暴力)的更多相关文章
- (KMP灵活运用 利用Next数组 )Theme Section -- hdu -- 4763
http://acm.hdu.edu.cn/showproblem.php?pid=4763 Theme Section Time Limit: 2000/1000 MS (Java/Others) ...
- Theme Section - HDU 4763(KMP)
题目大意:给你一个串,从这个串里面找出一个前缀后缀中间相等的串的最大长度也就是 EAEBE,每个字母都代表一个串,E出现了三次,找出最长的那个E. 分析:我们知道KMP里面保存的就是前缀和后缀的最 ...
- HDU 4763:Theme Section(KMP)
http://acm.hdu.edu.cn/showproblem.php?pid=4763 Theme Section Problem Description It's time for mus ...
- HDU 4763 Theme Section (2013长春网络赛1005,KMP)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 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 ...
- HDU 4763 Theme Section(KMP灵活应用)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu4763 Theme Section
地址:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题目: Theme Section Time Limit: 2000/1000 MS (Java/O ...
- Theme Section(KMP应用 HDU4763)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- centos7 安装jenkenis
安装Java 看到当前系统Java版本的命令: java -version 如果显示Java版本号,说明已经正确安装,如果显示没有该命令,需要安装Java: sudo yum install java ...
- rest的Web服务端获取http请求头字段
如上图所示 输出的i就是获取的头字段的值 (仅自己记录)
- WebGL——osg框架学习一
从今天开始,我们开始正式的学习osg框架,今天我们学习的是osg的渲染模块,我们来看一下代码结构. 所有DrawXXX的js模块都是渲染的模块,我们逐一来简单介绍一下,第一个Drawable.js,这 ...
- TPO-21 C1 Find a building for orientation
TPO-21 C1 Find a building for orientation 第 1 段 1.Listen to a conversation between a student and a p ...
- 炸!分享美团面试关于selenium的面试题
个人分类: 软件测试 编辑 在这个互联网技术快速迭代的时代,每个测试员都知道技术对于职业发展的重要性,那些技术好的测试员不仅薪资高,而且大多数集中在一线互联网企业工作,让人感觉非常高大上的同时,也想去 ...
- Mac环境搭建以太坊私有链
原文地址: 石匠的blog 为了测试以太坊智能合约,最方便的是在本地搭建一个以太坊私有链.在mac上搭建环境主要需要以下步骤. geth安装 geth是go-ethereum的简写,是一个用go语言编 ...
- [redis] 几种redis数据导出导入方式
环境说明: 172.20.0.1 redis源实例 172.20.0.2 redis目标实例 172.20.0.3 任意linux系统 一.redis-dump方式 1.安装redis-dump工具 ...
- Python20-Day05
一.模块与包 1.模块 什么是模块? 在python中,模块可以分为四个通用类别: 1. 使用python编写的.py文件 2. 已经被编译为共享库或DLL的c或者c++扩展 3. 把一系列模块组织到 ...
- spring boot之配置跨域
在启动类中配置 @Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurer() { @Override p ...
- 20135234mqy
北京电子科技学院(BESTI) 实 验 报 告 课程:Java实验 班级:1352 姓名: mqy 学号:20135234 成绩: 指导教师 ...