Theme Section HDU
来源:互联网 发布:linux top命令 编辑:程序博客网 时间:2024/06/05 18:48
题目传送门
题意:给你一个字符串,你在这个字符串中间找一个最长的字串,可以和开头和结尾相同。
思路:这个题还是比较暴力的,直接KMP和枚举就可以了。
#include <algorithm>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <list>#include <map>#include <queue>#include <set>#include <stack>#include <string>#include <vector>#define MAXN 1010000#define MAXE 100#define INF 1000000000#define MOD 10001#define LL long long#define ULL unsigned long long#define pi 3.14159using namespace std;int nex[MAXN];bool vis[MAXN];string str;int n, m;int max_length;void get_nex() { memset(nex, 0, sizeof(nex)); for (int i = 1, j = 0; i < n; ++i) { while (j && str[i] != str[j]) { j = nex[j]; } if (str[i] == str[j]) { j++; } nex[i + 1] = j; }}void KMP(int pos, int l) { for (int i = pos, j = 0; i < l; i++) { while (j && str[i] != str[j]) j = nex[j]; if (str[i] == str[j]) j++; if (j > m) return; if (j > max_length) max_length = j; }}int main() { std::ios::sync_with_stdio(false); int T; cin >> T; for (int kase = 1; kase <= T; ++kase) { cin >> str; n = (int) str.length(); if (n < 3) { cout << 0 << endl; } else { get_nex(); memset(vis, false, sizeof(vis)); max_length = 0; for (int i = min(nex[n], n / 3); i >= max_length && i >= 1; --i) { m = i; KMP(i, n - i); } cout << max_length << endl; } } return 0;}
阅读全文
0 0
- HDU 4763 Theme Section
- hdu 4763 Theme Section
- hdu 4763 Theme Section
- HDU-4763 Theme Section
- HDU 4763 Theme Section
- HDU 4673 Theme Section
- Hdu-4763 Theme Section
- hdu 4763 Theme Section
- hdu 4763 Theme Section
- KMP Theme Section HDU
- HDU 4763Theme Section
- hdu 4763 Theme Section
- hdu 4763 Theme Section
- Theme Section HDU
- Theme Section HDU
- hdu 4763Theme Section
- KMP-hdu-4763-Theme Section
- hdu 4763 Theme Section (双哈希)
- 解析器
- Git图标不显示
- 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。
- ajax返回错误的调试方法
- 51nod 1115 最大M子段和 V3 (链表)
- Theme Section HDU
- 文章标题
- 一起学Netty(十五)之 AttributeMap属性
- Moment.js 2.10.6 JavaScript 日期处理类库
- js根据字符串创建日期对象
- pata1063
- 源码的编译安装
- 让用户id隐藏起来
- 公众号中淘宝内部优惠券商城