地址: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
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 the last trademark, the next task begins. The last task is followed by a line containing zero.
aabbaabb
abbababb
bbbbbabb
2
xyz
abc
0
IDENTITY LOST
思路: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的更多相关文章
-
hdu2328 Corporate Identity【string库使用】【暴力】【KMP】
Corporate Identity Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
-
hdu2328 Corporate Identity 扩展KMP
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
-
kuangbin专题十六 KMP&;&;扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
-
[HDU2328]Corporate Identity(后缀数组)
传送门 求 n 个串的字典序最小的最长公共子串. 和 2 个串的处理方法差不多. 把 n 个串拼接在一起,中间连上一个没有出现过的字符防止匹配过界. 求出 height 数组后二分公共子串长度给后缀数 ...
-
POJ-3450 Corporate Identity (KMP+后缀数组)
Description Beside other services, ACM helps companies to clearly state their “corporate identity”, ...
-
hdu 2328 Corporate Identity(kmp)
Problem Description Beside other services, ACM helps companies to clearly state their “corporate ide ...
-
(KMP 暴力)Corporate Identity -- hdu -- 2328
http://acm.hdu.edu.cn/showproblem.php?pid=2328 Corporate Identity Time Limit: 9000/3000 MS (Java/Oth ...
-
POJ3450 Corporate Identity 【后缀数组】
Corporate Identity Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 7662 Accepted: 264 ...
-
POJ3450 Corporate Identity —— 后缀数组 最长公共子序列
题目链接:https://vjudge.net/problem/POJ-3450 Corporate Identity Time Limit: 3000MS Memory Limit: 65536 ...
随机推荐
-
[CentOS 7] 安装nginx第一步先搭建nginx服务器环境
简要地介绍一下,如何在CentOS 7中安装nginx服务器 方法/步骤 下载对应当前系统版本的nginx包(package) # wget http://nginx.org/packages/ ...
-
从InputStream到String_写成函数
String result = readFromInputStream(inputStream);//调用处 //将输入流InputStream变为String public String readF ...
-
mac_Alfred_快捷设置
1.安装(不说了去 Google 吧) 2.基础快捷键:option+space 3.打开应用程序:Alfred 几乎是一切程序的入口,你再也不需要找妈妈要开始菜单了.用快捷键呼出Alfred,输入任 ...
-
Gson解析复杂的Bean类实现Parcelable
import java.util.ArrayList; import android.os.Parcel; import android.os.Parcelable; import android.s ...
-
AD7928
实验室板子soc-de1自带的7928芯片,下面记录一下它的参数 吞吐速率 : 1MSPS 吞吐速率 : 是指ADC器件单位时间内能处理的任务数或输出结果的数量.单位:SPS(Samples per ...
-
mysql替换字符串
今天要替换数据库里的所有字符串 例如把http改成https UPDATE table_name set colum_name=REPLACE(colum_name,'http','https')
-
mvp 在 flutter 中的应用
在 Android 应用程序开发过程中,我们经常会用到一些所谓的架构方法,如:mvp,mvvm,clean等.之所以这些方法会被推崇是因为他们可以大大的解耦我们的代码的功能模块,让我们的代码在项目中后 ...
-
Hbase1.1.x Java版之批量查删操作
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.*; import org.apache.had ...
-
Android Webview中解决H5的音视频不能自动播放的问题
在开发webview的时候,当加载有声音的网页的时候,声音不会自动播放, 解决方法:在webview中调用js方法.这个方法需要在webview的setWebViewClient方法之后在onPage ...
-
以最省内存的方式把大图片加载到内存及获取Exif信息和获取屏幕高度和宽度的新方法
我们在加载图片时经常会遇到内存溢出的问题,图片太大,我们加载图片时,一般都是用的如下一般方法(加载本地图片): /** * 不作处理,去加载图片的方法,碰到比较大的图片会内存溢出 */ private ...