poj_3450 Corporate Identity(KMP+枚举)
来源:互联网 发布:淘宝详情模板下载 编辑:程序博客网 时间:2024/06/05 16:41
【题目】
点击这里
【思路】
同poj_3080 Blue Jeans,依然秒AC(1100ms << 3000ms demanded)
【代码】
#include <stdio.h>#include <string.h>char a[4002][201];int next[202];void getNext(char t[], int x, int y){ int i=x, j=x-1; next[i]=j; while (i<y+1) if (j==x-1 || t[i]==t[j]) { i++;j++; if (t[i]!=t[j]) next[i]=j; else next[i]=next[j]; } else j=next[j];}int kmpMain(char t[], int x, int y, char s[]){ int i=0, j=x, sLen=strlen(s); while (i<sLen && j<y+1) if (j==x-1 || s[i]==t[j]){i++;j++;} else j=next[j]; if (j==y+1) return 1; else return -1;}int comp(char s[], int x, int y, int len){ int i, ans=x; for (i=0;i<len;i++) { if (s[x+i]<s[y+i]) {ans=x;break;} if (s[x+i]>s[y+i]) {ans=y;break;} } return ans;}int main(){ int m,i,j,k; while (1) { scanf("%d",&m); if (m==0) break; scanf("%s",a[1]); int small=strlen(a[1]), ls=1; for (j=2;j<=m;j++) {scanf("%s",a[j]); int sLen=strlen(a[j]); if (sLen<small){small=sLen; ls=j;}} strcpy(a[0],a[ls]); int flag=0,ans; for (j=small;j>0;j--) { for (k=0;k<=small-j;k++) { getNext(a[0],k,k+j-1); int flag1=0,p; for (p=1;p<=m;p++) if (kmpMain(a[0],k,k+j-1,a[p])<0) {flag1=1;break;} if (flag1==0) if (flag==0) {flag=1;ans=k;} else ans=comp(a[0],ans,k,j); } if (flag==1) { for (k=ans;k<ans+j;k++) printf("%c",a[0][k]); printf("\n"); break; } } if (flag==0) printf("IDENTITY LOST\n"); } return 0;}
0 0
- poj_3450 Corporate Identity(KMP+枚举)
- 【扩展KMP】POJ_3450| HDU_2328 Corporate Identity
- Corporate Identity (KMP+暴力枚举)
- poj Corporate Identity 3450 (KMP&&枚举) 好题
- POJ 3450 Corporate Identity 暴力枚举+KMP
- POJ 3450Corporate Identity(暴力枚举+KMP)
- POJ 3450--Corporate Identity【KMP && 枚举】
- HDU2328 Corporate Identity(KMP)
- hdu 2328 Corporate Identity (KMP)
- HDU 2328 Corporate Identity (暴力 | kmp)
- 【poj 3450 Corporate Identity 】 KMP(暴力)
- 【kmp】Corporate Identity HDU
- hdu 2328 Corporate Identity(KMP)
- POJ-3450-Corporate Identity(KMP)
- POJ 3450 Corporate Identity (KMP+暴搞)
- poj 3450 Corporate Identity(二分长度 + 暴力kmp)
- POJ 题目3450 Corporate Identity(KMP 暴力)
- POJ-3450 Corporate Identity(KMP/后缀数组)
- 二叉树
- Spark实战-Spark SQL(一)
- java小的误区
- 快速求幂取模
- 图(拓扑排序)2
- poj_3450 Corporate Identity(KMP+枚举)
- 图(拓扑排序)3
- ubuntu14.04中搭建qt for android环境
- 搜索(枚举) 1
- 算法学习--二叉树
- 搜索(枚举)2
- 搜索(枚举)3
- XML解析
- HIBERNATE的N+1查询问题