hdu 5371 Hotaru's problem(manachar)
来源:互联网 发布:语音网络 编辑:程序博客网 时间:2024/05/20 03:39
题目链接:hdu 5371 Hotaru's problem
#include <cstdio>#include <cstring>#include <vector>#include <set>#include <algorithm>using namespace std;typedef pair<int,int> pii;typedef set<int>::iterator iter;const int maxn = 100005 * 2;int N, A[maxn];set<int> S;vector<pii> V;/********* mannachar *************/int rad[maxn], str[maxn];void manachar(int* tmpstr) {int len = N, mv = 0;str[mv++] = -2;for (int i = 1; i <= len; i++) {str[mv++] = -1;str[mv++] = tmpstr[i];}str[mv++] = -1;int ret = 0, mix = 0, idx = 0;for (int i = 1; i <= mv; i++) {if (mix > i)rad[i] = min(rad[2 * idx - i], mix - i);elserad[i] = 1;for ( ; str[i - rad[i]] == str[i + rad[i]]; rad[i]++) {if (mix < i + rad[i]) {mix = i + rad[i];idx = i;}}if (str[i] == -1)V.push_back(make_pair(rad[i]-1, i/2));}}/*********************************/void init () {V.clear();scanf("%d", &N);for (int i = 1; i <= N; i++)scanf("%d", &A[i]);manachar(A);sort(V.begin(), V.end());}int solve () {int ret = 0;S.clear();for (int i = V.size() - 1; i >= 0; i--) {int len = V[i].first;int idx = V[i].second;iter it = S.upper_bound(idx + len / 2);if (it != S.begin()) {it--;int iidx = *it;ret = max(ret, (iidx - idx) * 3);}it = S.lower_bound(idx - len / 2);if (it != S.end()) {int iidx = *it;ret = max(ret, (idx - iidx) * 3);}S.insert(idx);}return ret;}int main () {int cas;scanf("%d", &cas);for (int kcas = 1; kcas <= cas; kcas++) {init ();printf("Case #%d: %d\n", kcas, solve());}return 0;}
0 0
- hdu 5371 Hotaru's problem(manachar)
- HDU 5371 Hotaru's problem(Manacher)
- HDU 5371 Hotaru's problem
- HDU 5371 Hotaru's problem
- HDU 5371 Hotaru's problem
- HDU 5371 Hotaru's problem
- hdu 5371 Hotaru's problem
- HDU 5371 Hotaru's problem
- hdu5371 Hotaru's problem manachar回文串算法+枚举
- HDU 5371 Hotaru's problem (Manacher+暴力)
- HDU 5371 Hotaru's problem(Manacher算法+贪心)
- HDU 5371 Hotaru's problem(Manacher算法)
- hdu 5371 Hotaru's problem(manacher+尺取法)
- hdu 5371 Hotaru's problem (Manacher算法+枚举)
- Manacher算法(Hotaru's problem,HDU 5371)
- HDU 5371 - Hotaru's problem(Manacher算法)
- hdu 5371 Hotaru's problem (Manacher算法)
- hdu 5371 Hotaru's problem【manacher】
- 双系统Window+Linux,卸载Linux
- 二分查找(非递归实现和递归实现)
- 深入集合框架之Hashtable源码剖析
- 微软的Chart控件的用法-折线图
- 编译原理——词法分析器
- hdu 5371 Hotaru's problem(manachar)
- SonarQube代码质量管理平台安装与使用
- C++之迭代器(iterator)与集合(vector)
- OC常用代码,每个OC开发者必备知识...
- 面试题:比较两个集合是否相等?
- 【黑马程序员】Foundation框架NSArray
- ResumeLayout、SuspendLayout、PerformLayout
- 二叉树的最小深度
- ds18b20使用教程