hdu 4763 Theme Section 扩展kmp
来源:互联网 发布:ubuntu 卸载qq 编辑:程序博客网 时间:2024/05/22 15:42
扩展kmp,next表求前缀和后缀的公共部分同时记录这个前缀是否在这个总串去除它长度的前缀和后缀后依然存在,最后拿出符合结果的最大前缀
#include<cstdio>#include<algorithm>#include<iostream>#include<cstring>using namespace std;char a[1000010];int nexta[1000010],la;bool sym[1000010];int getNext(){ int i=0,j=-1; nexta[0] = -1; while(i<la) { if(a[i]==a[j]||j==-1) { i++,j++; nexta[i] = j; if(i-1-j>=j-1&&i-1<=la-1-j)sym[j] = true; } else j = nexta[j]; } int pre = nexta[la],ans = 0; while(pre) { if(sym[pre]) { ans = pre; break; } else pre = nexta[pre]; } return ans;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%s",a); la = strlen(a); for(int i=0;i<=la;i++)sym[i]=0; printf("%d\n",getNext()); } return 0;}
0 0
- hdu 4763 Theme Section (扩展kmp)
- hdu 4763 Theme Section 扩展kmp
- hdu 4763 Theme Section(扩展kmp+线段树)
- KMP-hdu-4763-Theme Section
- hdu 4763 Theme Section(KMP)
- hdu 4763 Theme Section kmp
- HDU 4763 Theme Section(KMP)
- hdu 4763 Theme Section(KMP)
- hdu 4763 Theme Section KMP
- HDU 4763 Theme Section(KMP)
- hdu 4763 Theme Section(KMP)
- HDU - 4763 Theme Section KMP
- Hdu 4763 Theme Section KMP
- KMP Theme Section HDU
- HDU 4763 Theme Section(KMP)
- hdu 4763 Theme Section(KMP水题)
- HDU 4763 Theme Section(KMP)
- 【HDU】 4763 Theme Section (KMP)
- fibonacci数列 java实现
- Codeforces 689.C Mike and Chocolate Thieves 二分+数学
- java之静态
- 【OpenCV笔记 03】OpenCV头文件探秘
- uC/OS-II内核架构解析---uC/OS-II任务管理
- hdu 4763 Theme Section 扩展kmp
- The program 'java' can be found in the following packages
- 数据泵expdp,impdp
- c# fixed 语句
- SpringMVC入门之一
- uC/OS-II内核架构解析---uC/OS-II通信与同步
- hadoop
- "SurfaceView控件"-出现的问题记录
- PHPMailer发匿名邮件及Extension missing: openssl的解决