【manacher】hud 5371 Hotaru's problem
来源:互联网 发布:淘宝图库在哪里 编辑:程序博客网 时间:2024/05/23 02:21
http://acm.hdu.edu.cn/showproblem.php?pid=5371
//#pragma comment(linker, "/STACK:102400000,102400000")#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;typedef long long LL;typedef unsigned long long ULL;typedef pair<int,int> PII;const int INF = 0x3f3f3f3f;/*manacher 处理每个字符最长回文串, 暴力处理最长答案,贪心优化一下.*/const int N = 100010;int s[N*2], p[N*2];int main(){ int T,n,m; scanf("%d",&T); for(int cas=1; cas<=T; cas++){ scanf("%d",&n); s[0] = -2; for(int i=1; i<n*2; i+=2){ s[i] = -1; scanf("%d",&s[i+1]); } s[2*n+1] = -1; s[2*n+2] = -3; m = 2*n+2;// for(int i=1; i<=m; i++)// printf("%d ",s[i]);// puts(""); int pid=0; p[0] = p[m] = 0; for(int i=1; i<m; i++){ if(i<pid+p[pid]) p[i] = min(p[2*pid-i],p[pid]+pid-i); else p[i] = 1; while(s[i+p[i]]==s[i-p[i]]) p[i]++; if(pid+p[pid] < i+p[i]) pid = i; } int ans = 0; for(int i=1; i<m; i+=2){ for(int j=i+p[i]-1; j>ans+i; j-=2){ if(p[j] >= j-i) { ans = j-i; break; } } } printf("Case #%d: %d\n",cas,ans/2*3); } return 0;}
阅读全文
0 0
- 【manacher】hud 5371 Hotaru's problem
- HDOJ-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算法)
- HDU 5371 Hotaru's problem Manacher+Set
- HDU 5371 Hotaru's problem(Manacher)
- [HDU 5371]Hotaru's problem:Manacher
- hdu5371 Hotaru's problem (Manacher)
- [Manacher] hdu5371 Hotaru's problem
- HDU 5371 Hotaru's problem (Manacher+暴力)
- HDU 5371 Hotaru's problem Manacher + set维护
- 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 + 线段树
- java简单实现的response
- Flask学习日记2
- (ACM)Number Sequence
- ZOJ Problem Set
- vue学习进度记录
- 【manacher】hud 5371 Hotaru's problem
- 7-如何解析爬虫爬取回来的数据
- [Machine Learning] 梯度下降法的三种形式BGD、SGD以及MBGD
- 第四周项目2建设“单链表”算法库
- BZOJ1303(CQOI2009)[中位数图]--奇技淫巧
- Impala在国双的使用(二):AIOps在Impala mem_limit调优的实践
- Scrapy爬虫(2)爬取新浪旅游图片
- 刷题笔记:牛客字符串专项练习3
- python3 导入本地 package 问题