地址: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. 判断ActiveX控件是Desgin Mode还是Runtime Mode

    对于MFC COleControl::AmbientUserMode Determines if the Container is in design mode or user mode. BOOL ...

  2. hdu 1520(简单树形dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 思路:dp[u][0]表示不取u的最大价值,dp[u][1]表示取u的最大价值,于是有dp[u] ...

  3. (转)有关Queue队列

    Queue Queue是python标准库中的线程安全的队列(FIFO)实现,提供了一个适用于多线程编程的先进先出的数据结构,即队列,用来在生产者和消费者线程之间的信息传递 基本FIFO队列 clas ...

  4. vue2.0中,由于页面完成之后dom还未加载完成如何进行操作

    再vue中,当页面加载完成以后,dom还没有加载,是无法获取进行操作的,但是在vue2.0中提供了一个方法:this.$nextTick,在这个回调函数里面写dom操作即可: 如下代码: create ...

  5. Shell脚本编程与文件系统修复

    导读 Linux基金会发起了LFCS认证(Linux 基金会认证系统管理员)Linux Foundation Certified Sysadmin,这是一个全新的认证体系,旨在让世界各地的人能够参与到 ...

  6. JqGrid 获取所有数据

    jqGrid使用本地数据时,当jqGrid配置的rowNum小于本地总数据量(records属性记录总数据,可以通过records获取到本地总数据量),调用getRowData方法获取到的只是显示的部 ...

  7. 【BZOJ3585/3339】mex 莫队算法+分块

    [BZOJ3585]mex Description 有一个长度为n的数组{a1,a2,...,an}.m次询问,每次询问一个区间内最小没有出现过的自然数. Input 第一行n,m. 第二行为n个数. ...

  8. Yii2的主从数据库设置

    项目做大了,数据库主从还是不可少的.使用Yii框架开发,如何设置数据库的主从呢?其实很简单. 先说一个主数据库服务器和多个从数据库服务器的情况,修改配置文件 config/db.php ,其中 sla ...

  9. 【opencv】 solvepnp 和 solvepnpRansac 求解 【空间三维坐标系 到 图像二维坐标系】的 三维旋转R 和 三维平移 T 【opencv2使用solvepnp求解rt不准的问题】

    参考: pnp问题 与 solvepnp函数:https://www.jianshu.com/p/b97406d8833c 对图片进行二维仿射变换cv2.warpAffine() or 对图片进行二维 ...

  10. Best Reward---hdu3613(manacher 回文串)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3613 题意就是给你一个串s 然后求把s分成两部分之后的价值总和是多少,分开的串 如果是回文那么价值就是 ...