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.

扩展KMP裸题

 #include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std; const int maxn=;
int nxt[][maxn],ext[][maxn];
char s[][maxn];
int len[],ans[maxn]; void EKMP(char s[],char t[],int lens,int lent,int c){
int i,j,p,l,k;
nxt[c][]=lent;j=;
while(j+<lent&&t[j]==t[j+])j++;
nxt[c][]=j;
k=;
for(i=;i<lent;i++){
p=nxt[c][k]+k-;
l=nxt[c][i-k];
if(i+l<p+)nxt[c][i]=l;
else{
j=max(,p-i+);
while(i+j<lent&&t[i+j]==t[j])j++;
nxt[c][i]=j;
k=i;
}
} j=;
while(j<lens&&j<lent&&s[j]==t[j])j++;
ext[c][]=j;k=;
for(i=;i<lens;i++){
p=ext[c][k]+k-;
l=nxt[c][i-k];
if(l+i<p+)ext[c][i]=l;
else{
j=max(,p-i+);
while(i+j<lens&&j<lent&&s[i+j]==t[j])j++;
ext[c][i]=j;
k=i;
}
}
} int main(){
int n;
while(scanf("%d",&n)!=EOF&&n){
memset(ans,0x3f,sizeof(ans));
for(int i=;i<=n;++i)scanf("%s",s[i]);
for(int i=;i<=n;++i)len[i]=strlen(s[i]);
int maxx=;
for(int i=;i<len[];++i){
for(int j=;j<=n;++j){
int cnt=;
EKMP(s[j],s[]+i,len[j],len[]-i,j);
for(int k=;k<len[j];++k){
if(ext[j][k]>cnt)cnt=ext[j][k];
}
if(cnt<ans[i])ans[i]=cnt;
}
if(ans[i]>maxx)maxx=ans[i];
}
if(!maxx)printf("IDENTITY LOST\n");
else{
string str[];
int cnt=;
for(int i=;i<len[];++i)if(ans[i]==maxx){
str[++cnt]=string(s[]+i,ans[i]);
}
sort(str+,str+cnt+);
cout<<str[]<<endl;
}
}
return ;
}

hdu2328 Corporate Identity 扩展KMP的更多相关文章

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

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

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

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

  3. hdu2328 Corporate Identity

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2328 题目: Corporate Identity Time Limit: 9000/3000 MS (J ...

  4. POJ 题目3450 Corporate Identity(KMP 暴力)

    Corporate Identity Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5493   Accepted: 201 ...

  5. POJ 3450 Corporate Identity (KMP,求公共子串,方法很妙)

    http://blog.sina.com.cn/s/blog_74e20d8901010pwp.html我采用的是方法三. 注意:当长度相同时,取字典序最小的. #include <iostre ...

  6. POJ 3450 Corporate Identity (KMP+暴搞)

    题意: 给定N个字符串,寻找最长的公共字串,如果长度相同,则输出字典序最小的那个. 找其中一个字符串,枚举它的所有的字串,然后,逐个kmp比较.......相当暴力,可二分优化. #include & ...

  7. POJ 3450 Corporate Identity(KMP)

    [题目链接] http://poj.org/problem?id=3450 [题目大意] 求k个字符串的最长公共子串,如果有多个答案,则输出字典序最小的. [题解] 我们对第一个串的每一个后缀和其余所 ...

  8. HDU - 2328 Corporate Identity(kmp+暴力)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2328 题意:多组输入,n==0结束.给出n个字符串,求最长公共子串,长度相等则求字典序最小. 题解:(居 ...

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

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

随机推荐

  1. 【原创】QT简单计算器

    代码 //main.cpp #include "calculator_111.h" #include <QtWidgets/QApplication> int main ...

  2. SpringBoot 上传、下载(四)

    工程目录结构 完整代码: 1.pom.xml 首先当然是添加依赖,用到thymeleaf模板渲染html页面 <project xmlns="http://maven.apache.o ...

  3. 从头入手jenkins

    前段时间项目处在测试阶段.5个测试妹子围着转,你不知道幸福的啊. 项目一共有开发.测试.生产三个环境,每次打包要切换分支代码,然后使用Xcode打包,然后生成ipa,再上传到蒲公英或者fir给测试妹子 ...

  4. Linux音频驱动学习之:(2)移植wm8976声卡驱动(linux-3.4.2)

    1.wm8976驱动程序: /* * wm8976.h -- WM8976 Soc Audio driver * * This program is free software; you can re ...

  5. 界面控件DevExpress发布v18.2.5|附下载

    DevExpress Universal Subscription(又名DevExpress宇宙版或DXperience Universal Suite)是全球使用广泛的.NET用户界面控件套包,De ...

  6. ssh 免密登陆

    A 要免密码登录要B 那么需要在A电脑上使用命令 ssh-keygen -t rsa 在~/.ssh/ 目录下生成id_rsa.pub 这个文件,然后将这个文件的内容拷到B电脑de ~/.ssh/au ...

  7. matla互相关协方差的计算和理解

    计算相关函数和协方差的MATLAB函数 MATLAB信号处理工具箱提供了计算随机信号相关函数xcorr. 函数xcorr用于计算随机序列自相关和互相关函数.调用格式为: [c,lags]=xcorr( ...

  8. SharePoint Framework 企业向导(一)

    博客地址:http://blog.csdn.net/FoxDave 简介 SharePoint Framework(SPFx)是一个新的SharePoint用户接口扩展的开发模型,它用来补充现有的 ...

  9. synchronized(七)

    package com.bjsxt.base.sync006; /** * 死锁问题,在设计程序时就应该避免双方相互持有对方的锁的情况 * @author alienware * */public c ...

  10. 【python】pandas display选项

    import pandas as pd 1.pd.set_option('expand_frame_repr', False) True就是可以换行显示.设置成False的时候不允许换行 2.pd.s ...