poj 3450 KMP+暴力枚举(类似于3080)
来源:互联网 发布:tbc数据库 编辑:程序博客网 时间:2024/05/16 18:10
类似于3080 稍作改动,即可AC。。
#include<iostream>using namespace std;int next[205];char str[205];char ans[205];char s[5050][205];int h;int le;void get_next(char *T,int len){ int j=0,k=-1; next[0]=-1; while(j<len) { if(k==-1||T[j]==T[k]) { next[j+1]=k+1; j++;k++; } else k=next[k]; } //for(int i=0;i<len;i++) //printf("%d ",next[i]);}bool find(char *str){ int len=strlen(str); int i=0,j=0; while(i<=le&&j<len) { if(j==-1||s[h][i]==str[j]) { j++;i++; } else j=next[j]; } if(j==len) return true; else return false;}int main(){ int k,l,n; while(scanf("%d",&n)!=EOF&&n) { for(int i=0;i<n;i++) scanf("%s",s[i]); le=strlen(s[0]); int t_len=0; strcpy(ans,"\0"); for(int i=1;i<=le;i++) { for(int j=0;j<=le-i;j++) { for(k=j,l=0;k<i+j;k++,l++) str[l]=s[0][k]; str[l]='\0'; get_next(str,i); //for(int m=0;m<i;m++) //printf("%d ",next[m]); //system("pause"); for(h=1;h<n;h++) if(!find(str)) break; if(h==n) { if(t_len<i) { t_len=i; strcpy(ans,str); } else if(t_len==i) { if(strcmp(ans,str)>0) { strcpy(ans,str); } } } //else //printf("No\n"); } } if(ans[0]!='\0') printf("%s\n",ans); else printf("IDENTITY LOST\n"); }}
- poj 3450 KMP+暴力枚举(类似于3080)
- poj 3080 暴力法 KMP+暴力枚举
- POJ 3450 Corporate Identity 暴力枚举+KMP
- POJ 3450Corporate Identity(暴力枚举+KMP)
- POJ 3080 Blue Jeans 暴力枚举+KMP
- POJ 3080 Blue Jeans kmp+暴力枚举
- poj 3080 Blue Jeans 【KMP 暴力枚举】
- POJ 3080--Blue Jeans【KMP && 暴力枚举】
- POJ 3080 Blue Jeans(暴力枚举+KMP 类似POJ 3450)
- POJ 3080 Blue Jeans(暴力枚举+kmp)
- POJ 3080 Blue Jeans (KMP+暴力枚举)【模板】
- poj 3080 KMP+暴力
- POJ 1226 Substrings 暴力枚举+KMP算法
- [KMP或者暴力]POJ 3450 Corporate Identity
- poj 3450 Corporate Identity 【暴力KMP】
- 【poj 3450 Corporate Identity 】 KMP(暴力)
- [KMP或者暴力]POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans KMP+暴力
- hdu 1358 KMP
- hdu 1711 裸KMP
- hdu 2752 KMP(前后缀)
- poj 3461 KMP
- poj 3080 KMP+暴力
- poj 3450 KMP+暴力枚举(类似于3080)
- 组织行为学笔记:第十五章 组织中的个人
- 介绍一个可玩性蛮高的东西-路由器(附RG100AA-A的一点资料)
- 大三期末总结
- 【有上下界的网络流】
- Delphi XE Refactor重构功能简单说明
- 将资源文件转换为头文件嵌入到工程
- Nginx的部署和资料收集
- 学习JavaScript