hdu 2328 & poj 3450
来源:互联网 发布:竞彩预测软件 编辑:程序博客网 时间:2024/06/10 00:41
点击打开链接 点击打开链接
Corporate Identity
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2189 Accepted Submission(s): 843
Problem Description
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includes company logo but also other signs, like trademarks. One of such companies is Internet Building Masters (IBM), which has recently asked ACM for a help with their new identity. IBM do not want to change their existing logos and trademarks completely, because their customers are used to the old ones. Therefore, ACM will only change existing trademarks instead of creating new ones.
After several other proposals, it was decided to take all existing trademarks and find the longest common sequence of letters that is contained in all of them. This sequence will be graphically emphasized to form a new logo. Then, the old trademarks may still be used while showing the new identity.
Your task is to find such a sequence.
After several other proposals, it was decided to take all existing trademarks and find the longest common sequence of letters that is contained in all of them. This sequence will be graphically emphasized to form a new logo. Then, the old trademarks may still be used while showing the new identity.
Your task is to find such a sequence.
Input
The input contains several tasks. Each task begins with a line containing a positive integer N, the number of trademarks (2 ≤ N ≤ 4000). The number is followed by N lines, each containing one trademark. Trademarks will be composed only from lowercase letters, the length of each trademark will be at least 1 and at most 200 characters.
After the last trademark, the next task begins. The last task is followed by a line containing zero.
After the last trademark, the next task begins. The last task is followed by a line containing zero.
Output
For each task, output a single line containing the longest string contained as a substring in all trademarks. If there are several strings of the same length, print the one that is lexicographically smallest. If there is no such non-empty string, output the words “IDENTITY LOST” instead.
Sample Input
3aabbaabbabbababbbbbbbabb2xyzabc0
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<string>using namespace std;char f[4005][205];char ans[205];int Next[205];void GetNext(char *a){ Next[0]=-1; int i=0,j=-1; int le=strlen(a); while(i<le) { if(j==-1||a[i]==a[j]) { i++; j++; Next[i]=j; } else j=Next[j]; }}int kmp(char *a,char *b){ int len1=strlen(a),len2=strlen(b); int i=0,j=0; while(i<len2) { if(j==-1||b[i]==a[j]) { i++; j++; } else j=Next[j]; if(j==len1) return true; } return false;}int main(){ int n; while(scanf("%d",&n),n) { int ma=0; for(int i=0;i<n;i++) scanf("%s",f[i]); int len=strlen(f[0]); for(int i=len;i>0;i--) { for(int j=0;j<=len-i;j++) { char x[205]={0}; strncpy(x,f[0]+j,i); GetNext(x); int flag=1; for(int t=1;t<n;t++) { if(!kmp(x,f[t])) { flag=0; break; } } if(flag) { if(i>ma||(i==ma&&strcmp(ans,x)>0)) { ma=i; strcpy(ans,x); } } } } if(ma==0) printf("IDENTITY LOST\n"); else printf("%s\n",ans); } return 0;}
阅读全文
0 0
- hdu 2328 & poj 3450
- poj hdu Tunnel Warfare
- hdu 1700 poj 2954
- poj 1177 && hdu 1828
- poj 3990 hdu 3694
- POJ 1466/HDU 1068
- hdu,poj 分类
- POJ 2238 && HDU 4294
- hdu 4009 && POJ 3164
- HDU 1043、POJ 1077
- 刷poj、hdu有感
- hdu 1540 && poj 2892
- hdu 1542 &&poj 1151
- hdu 1325 poj 1308
- poj 1503 hdu 1002
- POJ 1904 HDU 4685
- poj 2182||hdu 2711
- poj 3974 HDU 3068
- hdoj-1727Hastiness
- 素数判断的方法
- jQuery——详细总结
- python实现画一颗树和一片森林
- 模板_分离编译
- hdu 2328 & poj 3450
- ideavim使用
- bzoj 1106: [POI2007]立方体大作战tet(贪心+树状数组)
- lombok注解介绍
- 算法_02_BFPRT
- 银行金额小写转大写
- RNN和LSTM推导与实现
- 学习笔记 学习jvm 原理 最基本概念(编译与运行概念)
- mysql中整数类型后面的数字,是不是指定这个字段的长度?比如int(11),11代表11个字节吗?