codeforces 126B Password DP KMP
来源:互联网 发布:数据库怎么弄 编辑:程序博客网 时间:2024/05/17 03:29
题意:在一个字符串中求一字串,即可以在前缀中找到,也可以在后缀中找到,也可以在中间找到
做法来自自于ZeroClock
#include <iostream>#include <cstdio>#include <cstring>#define LMT 1000005/****KMP算法本质:在字符串中有一个字符,以这个字符为末尾的长度为N的子串(不包括末字符,N为所能取到的最大值),可以与字符串头字符构成的长度为N的字串匹配(不包括末字符,且保证末字符不等)。***///第一次的next是最大的,之后就逐个减小using namespace std;int hash[LMT],next[LMT],len;char str[LMT];void init(void){ int i=0,j=-1; next[0]=-1; while(i<len) { if(j==-1||str[i]==str[j]) { i++;j++;next[i]=j; } else j=next[j]; } for(i=0;i<len;i++) hash[next[i]]++;}int main(){ int i; scanf("%s",str); len=strlen(str); init(); i=len; while(next[i]>0) { if(hash[next[i]]) { for(int j=0;j<next[i];j++) printf("%c",str[j]); printf("\n"); return 0; } i=next[i]; } printf("Just a legend\n"); return 0;}
- codeforces 126B Password DP KMP
- codeforces 126B B. Password(kmp+dp)
- codeforces 126B Password KMP
- Codeforces 126B Password(KMP)
- codeforces 126B password KMP
- CodeForces 126B Password 【kmp】
- CodeForces 126B password KMP
- CodeForces 126B - Password 利用KMP
- codeforces 126B Password (kmp,next应用)
- codeforces 126B Password
- codeforces 126 B. Password
- codeforces 494B kmp+dp
- cf 126B-Password(KMP)
- Codeforces Beta Round #93 (Div. 1 Only)-B. Password(KMP)
- Obsessive String - CodeForces 494 B KMP+dp
- Codeforces 494B. Obsessive String KMP+DP
- [Codeforces 176B] Word Cut (脑洞+KMP+dp)
- CF 126B Password (KMP,利用next数组)
- 设置java的默认系统属性
- com.android.musicFx设置音效流程 -- 从app到AudioFlinger
- Ubuntu 10.04 配置gdm 实现window的Xmanager远程登录
- android 联系人 --- 读取usim卡的邮箱
- pythonchallenge_1
- codeforces 126B Password DP KMP
- 关于sim/usim的一些概念
- JSTL API
- 微信版中文计算器
- Asynctask 代码分析
- Python ElementTree的find,findall函数参数
- 初探类的字段.属性.方法.事件
- JSTL与EL
- 8086的地址ffff:ffff和0:ffef回绕问题