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 ...
随机推荐
- Nginx应用场景
1. Nginx应用场景 1)http服务器.Nginx可以独立的提供http服务,可以做网页静态服务器(也就是将静态文件放到nginx目录下,通过nginx来访问就ok) 2)虚拟主机,可以在一 ...
- Python学习环境搭建——VMware,Ubuntu,Anaconda,Pycharm
1.安装VMware虚拟机,版本是14.1.2(含注册码) 链接:https://pan.baidu.com/s/1ffNLONDjEMYDAenE36gRpA 密码:yazx 注:我的电脑分辨率较高 ...
- [硬件配置]记录Ubuntu 14.04 下安装无线网卡驱动解决无法连接WiFi的过程
新电脑安装了Ubuntu 14.04,但是网络连接中只有以太网而没有WiFi的选项. 打开System Setting系统设置-Software&Updates软件&更新-Additi ...
- RabbitMQ入门:发布/订阅(Publish/Subscribe)
在前面的两篇博客中 RabbitMQ入门:Hello RabbitMQ 代码实例 RabbitMQ入门:工作队列(Work Queue) 遇到的实例都是一个消息只发送给一个消费者(工作者),他们的消息 ...
- First Day!
刚申请博客第一天,多多关照! 小弟,给各位大佬递茶! 出现什么错误, 还请明确指出! 现在, 正在找工作, 如果有老哥, 公司缺人, 何不让老弟我去试试! 不入前端, 不知水深. 一入前端, 如入泥潭 ...
- js数组知识点总结及经典笔试题
1.判断数组 这是笔试里经常会出现的知识考察点,总结一下 (1)Array.isArray()方法判断 var a=[]; Array.isArray(a) //返回true var b='hello ...
- Lwip:原生态的Linux socket应用如何移植到Lwip上
lwIP - A Lightweight TCP/IP stack 在上一篇中,我们了解到在OpenFastPath上如何移植原生态的Linux Socket应用程序,那么,对于另外一个老牌的小型TC ...
- ubuntu16.04 CUDA, CUDNN 安装
这次介绍的是使用 tensorflow1.8, cuda9.0, cudnn7.0的版本 https://developer.nvidia.com/cuda-90-download-archive 下 ...
- Python模块xlwt对excel进行写入操作
python常用模块目录 1.安装 $ pip install xlwt 2.创建表格和工作表单写入内容 例子: import xlwt # 创建一个workbook 设置编码 workbook = ...
- 关于React面试题汇总
1.redux中间件 中间件提供第三方插件的模式,自定义拦截 action -> reducer 的过程.变为 action -> middlewares -> reducer .这 ...