hdu5371 Hotaru's problem 2015年多校第七场C题 最长回文串
来源:互联网 发布:php 刷新重复提交表单 编辑:程序博客网 时间:2024/06/05 19:26
题意很简单,就是分成连续三段,相邻的两段为回文,求这三段的最大长度。
11
1 2 3 4 3 2 1 2 3 4 5
在这组数据是,为0;
13
1 2 3 4 4 3 2 1 1 2 3 4 6
这组数据为12.
如果会最长回文的话,这道题就简单了,不会的可以先看看http://acm.uestc.edu.cn/bbs/read.php?tid=3258 ,会manacher的话,这道题就是一道水题了,只是时间卡得很紧,一不小心就上T;哎!说起来就是伤心事呀!
#include<stdio.h>#include<string.h>#include<math.h>#include<queue>#include<vector>#include<iostream>#include<string>#include<set>#include<map>#include<algorithm>using namespace std;#pragma comment(linker, "/STACK:1024000000,1024000000")#define nn 1000010#define LL long long#define ULL unsiged long long//#define mod 0x7fffffff#define mod 110010#define inf oxfffffffffff#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1// ((`'-"` `""-'`))// ) - - (// / (o _ o) \// \ ( 0 ) /// _'-.._ '=' _..-'_// /`;#'#'#. -. #'#'#;`\// \_)) '#' ((_/// #. ℃ ℃ ℃ .#// '#. 箔 A C! .#'// /'#. .#'\// _\\'#. .#'//_// (((___)'#'(___)))int str[nn*2];int p[nn*2],n;void pk(){ int i; int mx = 0; int id; for(i=1; i<n; i++) { if( mx > i ) p[i] = min( p[2*id-i], mx-i ); else p[i] = 1; for(; str[i+p[i]] == str[i-p[i]]; p[i]++); if( p[i] + i > mx ) { mx = p[i] + i; id = i; } }}int main(){ int t,kcase=1; scanf("%d",&t); while(t--) { scanf("%d",&n); str[0]='$'; str[1]='#'; for(int i=0;i<n;i++) { scanf("%d",&str[i*2+2]); str[i*2+3]='#'; } n=n*2+2; str[n]=0; pk(); int ans=0; for(int i=3;i<n;i+=2) { if(p[i]>ans) { for(int j=p[i];j>ans;j-=2)//改成j--会T的!丧心病狂呀! { if(p[i+j-1]>=j) { ans=j; break; } } } } printf("Case #%d: %d\n",kcase++,3*(ans-1)/2); } return 0;}
0 0
- hdu5371 Hotaru's problem 2015年多校第七场C题 最长回文串
- 【最长回文子串】【平衡树】[HDU5371]Hotaru's problem
- hdu5371 Hotaru's problem manachar回文串算法+枚举
- hdu5371 Hotaru's problem
- HDU5371 Hotaru's problem
- hdu5371 Hotaru's problem (Manacher)
- [Manacher] hdu5371 Hotaru's problem
- 【HDU5371】Hotaru's problem(Manacher + set)
- hdu5371(2015多校7)--Hotaru's problem(Manacher+线段树)
- hdu5371 Hotaru's problem(Manacher算法变形)
- hdu5371 Hotaru's problem(manacher 算法+枚举)
- Hotaru's problem(hdu5371+Manacher)多校7
- 字符串:HDU5371-Hotaru's problem(manacher 的应用)
- HDU 5371 (2015多校联合训练赛第七场1003)Hotaru's problem(manacher+二分/枚举)
- HDU 5371 Hotaru's problem(Manacher算法 回文串)
- HDU 5371(Hotaru's problem-2次回文串)
- HDU 5371(2015多校7)-Hotaru's problem(Manacher算法求回文串)
- 多校第七场 1003 hdu 5371 Hotaru's problem(manacher+set)
- poj 3080 Blue Jeans 【KMP 暴力枚举】
- nvme 驱动详解 之1
- POJ 3461 Oulipo(KMP)
- C/C++编译预处理:宏定义指令、文件包含指令、条件编译指令和特殊符号处理
- 《影响力》- 行走社会须知的干货
- hdu5371 Hotaru's problem 2015年多校第七场C题 最长回文串
- Google之大规模分布式系统的监控基础架构Dapper
- 基于注解的 Spring MVC 简单入门
- Slim Span
- java网络编程基础
- UE4学习笔记(二):c++与蓝图的交互
- 在Java中使用transient
- select2 4.02 实现类似google搜索条的 ajax remote data功能
- C语言编程需要注意的64位和32机器的区别