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 ...
随机推荐
- DMS路由表
DMS路由表: route add -p 53.90.146.0 mask 255.255.255.0 10.77.35.249 ================================= ...
- SpringMVC 完美解决PUT请求参数绑定问题(普通表单和文件表单)
一 解决方案 修改web.xml配置文件 将下面配置拷贝进去(在原有的web-app节点里面配置 其它配置不变) <!-- 处理PUT提交参数(只对基础表单生效) --> <filt ...
- 相机标定与矫正opencv+MATLAB
博客转载自:http://blog.csdn.net/Loser__Wang/article/details/51811347 本文目的在于记录如何使用MATLAB做摄像机标定,并通过opencv进行 ...
- 你这一辈子要用到的C数学函数都在这
两数相加 #include <stdio.h> int main(void){ int a = 10; //定义变量a, 把10 赋值给a int b = 20; //定义变量 ...
- 《图解 HTTP 》阅读 —— 第一章
第1章 了解web及网络基础 计算机与网络设备相互通信的规则称为协议,比如:如何探测到通信目标.由哪一边发起通信.使用那种语言进行通信.怎么结束通信等. TCP/IP 协议族按照层次分为以下四层:应用 ...
- ubuntu HackRF One相关环境搭建
本文内容.开发板及配件仅限用于学校或科研院所开展科研实验! 淘宝店铺名称:开源SDR实验室 HackRF链接:https://item.taobao.com/item.htm?spm=a1z10.1- ...
- 关于几个与IO相关的重要概念
1.读/写IO 读IO就是发指令从磁盘读取某段序号连续的扇区内容.指令一般是通知磁盘开始扇区位置,然后给出需要从这个初始扇区往后读取的连续扇区个数,同时给出动作是读还是写.磁盘收到这条指令就会按照指令 ...
- 关于nodejs中遇到mysql默认8小时连接断开机制的终极简单解决方案
由于mysql默认8小时连接无访问,就会断开.为此查了一下资料,有同种比较简单的解决方案: 1. 增加 MySQL 的 wait_timeout 属性的值. 修改 /etc/mysql/my.cnf文 ...
- 关于React面试题汇总
1.redux中间件 中间件提供第三方插件的模式,自定义拦截 action -> reducer 的过程.变为 action -> middlewares -> reducer .这 ...
- Sqlite数据库初步的了解
转载与:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2013/0714/1438.html 来自:泡在网上的日子. 和其他数据库一 ...