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 ...
随机推荐
- 写个hello world了解Rxjava
目录 什么是Rxjava? 在微服务中的优点 上手使用 引入依赖 浅谈分析Rxjava中的被观察者,观察者 spring boot 项目中使用Rxjava2 什么是Rxjava? 来自百度百科的解释 ...
- 接口自动化学习--mock
好久没有写学习的总结,都正月十二了,但还是要来个新年快乐鸭. 一直都在看imooc的一套java接口自动化实战课程,现在看到了尾部了,然后想到之前那些testng,mock,httpclient等都没 ...
- 【Unity Shader】(六) ------ 复杂的光照(上)
笔者使用的是 Unity 2018.2.0f2 + VS2017,建议读者使用与 Unity 2018 相近的版本,避免一些因为版本不一致而出现的问题. [Unity Sha ...
- python虚拟环境管理之virtualenv,virtualenvwrapper,pipenv,conda
虚拟环境的作用 使python环境拥有独立的包,避免污染原本的python环境.为不同的项目创建不同的环境可以避免安装的库过于庞大和相互干扰. 例如你想在同一台机器上开发用python2和python ...
- 32bit GM命令
GM 命令[32位服务端GM命令] //announce message this basicly tells a announcement on the whole server.. you can ...
- jenkins的时间与服务器的时间不一致
解决办法:
- CentOS删除安装的程序
以mysql举例: 首先查询安装包: rpm -qa|grep mysql 查询到的一个结果为:mysql-community-libs-5.7.13-1.el6.x86_64 yum 删除 yum ...
- Playfair加密
前面讲的不管是单码加密还是多码加密都属于单图加密,什么是单图加密和多图加密呢,简单来说单图加密就是一个字母加密一个字母,而多图加密就是一个字符组加密一个字符组.比如双图加密就是两个字母加密两个字母,这 ...
- LeetCode 455. Assign Cookies (C++)
题目: Assume you are an awesome parent and want to give your children some cookies. But, you should gi ...
- 微信小程序——节奏练耳 宣传页
节奏练耳是什么? 节奏练耳小程序是一款听音练习节奏的交互式小程序.节奏练耳第一大节是辨认六种音符的练习,剩余九大节的练习题中播放的音频是将时值长短不一的音符组合在一起,配合相应的节奏图片,以提高辨认节 ...