地址:http://acm.hdu.edu.cn/showproblem.php?pid=2328

题目:

Corporate Identity

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1599    Accepted Submission(s): 614

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.

 
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.

 
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
3
aabbaabb
abbababb
bbbbbabb
2
xyz
abc
0
 
Sample Output
abb
IDENTITY LOST
 
Source
 
Recommend
teddy
 

思路:kmp+暴力枚举

 #include <cstdio>
#include <cstring>
#include <iostream> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
const double eps=1e-;
const int K=1e6+;
const int mod=1e9+; int nt[K];
char sa[][],sb[];
void kmp_next(char *T,int *next)
{
next[]=;
for(int i=,j=,len=strlen(T);i<len;i++)
{
while(j&&T[i]!=T[j]) j=next[j-];
if(T[i]==T[j]) j++;
next[i]=j;
}
}
int kmp(char *S,char *T,int *next)
{
int ans=;
int ls=strlen(S),lt=strlen(T);
for(int i=,j=;i<ls;i++)
{
while(j&&S[i]!=T[j]) j=next[j-];
if(S[i]==T[j]) j++;
if(j==lt) ans++;
}
return ans;
}
int cmp(char *sb,int si,int st,int len)
{
for(int i=;i<len;i++)
if(sb[si+i]<sb[st+i])
return -;
else if(sb[si+i]>sb[st+i])
return ;
return ;
}
int main(void)
{
int t,n;
while(scanf("%d",&n)&&n)
{
for(int i=;i<=n;i++)
scanf("%s",sa[i]);
int len,st,se;
len=strlen(sa[]);
st=,se=-;
for(int i=;i<len;i++)
{
for(int j=i;j<len;j++)
{
sb[j-i]=sa[][j],sb[j-i+]='\0';
int ff=;
kmp_next(sb,nt);
for(int k=;k<=n&&ff;k++)
if(!kmp(sa[k],sb,nt))
ff=;
if(ff&&j-i>se-st)
st=i,se=j;
else if(ff&&j-i==se-st&&cmp(sa[],i,st,j-i+)<)
st=i,se=j;
}
}
if(se-st+<)
printf("IDENTITY LOST\n");
else
{
for(int i=st;i<=se;i++)
printf("%c",sa[][i]);
printf("\n");
} }
return ;
}

hdu2328 Corporate Identity的更多相关文章

  1. hdu2328 Corporate Identity【string库使用】【暴力】【KMP】

    Corporate Identity Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. hdu2328 Corporate Identity 扩展KMP

    Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...

  3. kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity

    Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...

  4. [HDU2328]Corporate Identity(后缀数组)

    传送门 求 n 个串的字典序最小的最长公共子串. 和 2 个串的处理方法差不多. 把 n 个串拼接在一起,中间连上一个没有出现过的字符防止匹配过界. 求出 height 数组后二分公共子串长度给后缀数 ...

  5. POJ-3450 Corporate Identity (KMP+后缀数组)

    Description Beside other services, ACM helps companies to clearly state their “corporate identity”, ...

  6. hdu 2328 Corporate Identity(kmp)

    Problem Description Beside other services, ACM helps companies to clearly state their “corporate ide ...

  7. (KMP 暴力)Corporate Identity -- hdu -- 2328

    http://acm.hdu.edu.cn/showproblem.php?pid=2328 Corporate Identity Time Limit: 9000/3000 MS (Java/Oth ...

  8. POJ3450 Corporate Identity 【后缀数组】

    Corporate Identity Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 7662   Accepted: 264 ...

  9. POJ3450 Corporate Identity —— 后缀数组 最长公共子序列

    题目链接:https://vjudge.net/problem/POJ-3450 Corporate Identity Time Limit: 3000MS   Memory Limit: 65536 ...

随机推荐

  1. jboss eap 6.4 部署 从weblogic迁移

    从weblogic10.3像jboss 6.4项目迁移,遇到的一些问题: 因为使用weblogic可以自定义公共的war包库,在使用jboss中,也采取项目依赖公共库的方式: 1.jboss中使用公共 ...

  2. ios 的EditBox点击空白处不隐藏的解决方案

    原因:参数少了前缀CC 解决方案:修改 cocos/platform/ios/CCEAGLView-ios.mm 中的 handleTouchesAfterKeyboardShow -(void) h ...

  3. 《C++ Primer Plus》第2章 开始学习C++ 学习笔记

    C++程序由一个或多个被称为函数的模块组成.程序从main()函数(全部小写)开始执行,因此该函数必不可少.函数由函数头和函数体组成.函数头指出函数的返回值(如果有的话)的类型和函数期望通过参数传递给 ...

  4. Android 中加载几百张图片做帧动画防止 OOM 的解决方案

    Android 中加载几百张图片做帧动画防止 OOM 的解决方案 最近,项目中有个需求:就是要做一个帧动画,按理说这个是很简单的!但是我能说这个帧动画拥有几百张图片吗?...... 填坑一 ---帧动 ...

  5. 解决 Unable to load native-hadoop library for your platform

    安装hadoop启动之后总有警告:Unable to load native-hadoop library for your platform... using builtin-java classe ...

  6. poj2396 Budget&&ZOJ1994 Budget[有源汇上下界可行流]

    Budget Time Limit: 5 Seconds      Memory Limit: 32768 KB      Special Judge We are supposed to make ...

  7. 电力项目十三--js添加浮动框

    修改page/menu/loading.jsp页面 首先,页面中引入浮动窗样式css <!-- 浮动窗口样式css begin --> <style type="text/ ...

  8. Spring Security OAuth2 token权限隔离

    由于项目OAuth2采用了多种模式,授权码模式为第三方系统接入,密码模式用于用户登录,Client模式用于服务间调用, 所有不同的模式下的token需要用  @PreAuthorize("h ...

  9. 170427、centos6.5配置duboo

    IP: 192.168.0.111 部署容器:apache-tomcat-7.0.57 端口:8080 1. 下载最新版的 Tomcat7: $wget http://mirrors.hust.edu ...

  10. Python--进阶处理9

    # =========================第九章:元编程============================= # ----------------在函数上添加包装器--------- ...