(KMP 暴力)Corporate Identity -- hdu -- 2328
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): 698 Accepted Submission(s): 281
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.
IDENTITY LOST
代码:
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std; #define M 40005
#define N 210 char s[M][N];
int Next[N]; void FindNext(char b[])
{
int i=, j=-, blen=strlen(b);
Next[] = -; while(i<blen)
{
if(j==- || b[i]==b[j])
Next[++i] = ++j;
else
j = Next[j];
}
} int KMP(char a[], char b[])
{
int i=, j=;
int alen=strlen(a), blen=strlen(b); FindNext(b); while(i<alen)
{
while(j==- || (a[i]==b[j] && i<alen && j<blen))
i++, j++;
if(j==blen)
return ;
j = Next[j];
}
return ;
} int main()
{
int n;
while(scanf("%d", &n), n)
{
int i, j, k, MinLen=, len;
char ss[N]; memset(s, , sizeof(s)); for(i=; i<n; i++)
{
scanf("%s", s[i]);
len = strlen(s[i]); if(len<MinLen)
{
MinLen = len;
memset(ss, , sizeof(ss));
strcpy(ss, s[i]);
}
} char b[N]="{";
int index=; for(i=MinLen; i>; i--)
{
for(j=; j<=MinLen-i; j++)
{
char a[N]; memset(a, , sizeof(a)); strncpy(a, ss+j, i); for(k=; k<n; k++)
{
if(KMP(s[k], a)==)
break;
} if(k==n && strcmp(a, b)<)
{
index = i;
strcpy(b, a);
} if(index && j==MinLen-i)
i=-, j=;
}
} if(index)
printf("%s\n", b);
else
printf("IDENTITY LOST\n"); }
return ;
}
(KMP 暴力)Corporate Identity -- hdu -- 2328的更多相关文章
- Corporate Identity - HDU 2328(多串求共同子串)
题目大意:给你N(2-4000)个字符串,求出来他们的共同子串 分析:因为上次就说了再出现这种题就不用那种暴力的做法了,于是看了一些别的知识,也就是后缀树,把一个字符串的所有的后缀全部都加入字典树 ...
- kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- hdu 2328 Corporate Identity(kmp)
Problem Description Beside other services, ACM helps companies to clearly state their “corporate ide ...
- hdu2328 Corporate Identity【string库使用】【暴力】【KMP】
Corporate Identity Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- POJ 题目3450 Corporate Identity(KMP 暴力)
Corporate Identity Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5493 Accepted: 201 ...
- POJ-3450 Corporate Identity (KMP+后缀数组)
Description Beside other services, ACM helps companies to clearly state their “corporate identity”, ...
- hdu2328 Corporate Identity 扩展KMP
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- hdu2328 Corporate Identity
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2328 题目: Corporate Identity Time Limit: 9000/3000 MS (J ...
- N - Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
随机推荐
- Can not find the tag library descriptor for "http://www.springframework.org/tags"
1.Download the Spring dependency jar2.Place it to the lib folder path is /WEB-INF/lib/spring.jar 3.T ...
- hadoop无法启动常见原因
1.Could not chdir to home directory /home/USER: Permission denied 启动datanode时会报这个错误,尝试利用ssh登录datanod ...
- js中常见的创建对象的方法
前两天好好的把高程对象那一块又读了下,顺便写点笔记.补一句:代码都测试过了,应该没有问题的.可以直接拿到控制台跑! 1.工厂模式 function person(name, age, job) { v ...
- centos7 升级python2.7 到python3.6(Centos7 安装Anaconda)
Anaconda 下载 https://www.anaconda.com/download/#linux 下载文件 Anaconda3-5.2.0-Linux-x86_64.sh bash Anaco ...
- electron 大体结构
1.Electron支持的平台: OS XWindowsLinux 2.一个标准的electron app包含的结构: Windows 或是 Linux中:electron/resources/app ...
- ValueError: update only works with $ operators
问题:在执行pymongo的update语句时,提示了ValueError: update only works with $ operators 脚本:db.user.update_one({&qu ...
- IE6 PNG不透明问题 (只解决img标签的图片)
<script type='text/javascript' src="/script/ie6.pngfix.js"></script> 会让一些posit ...
- Django之ORM使用以及模板语言
一.ORM版增删改查 1.ORM的语句 1.类名.objects.all() --> 返回一个列表 2.类名.objects.filter() --> 返回一 ...
- IO模型与select,poll,epoll
五种:阻塞,非阻塞,IO复印,信号驱动,异步. select,poll,epoll select: 典型用32个32位的整数表示1024个描述符,并发的局限. poll:功能同上,但数据结构不一样(链 ...
- python之字典【dict】
#Auther Bob#--*--conding:utf-8 --*-- #创建一个字典dictdic1 = {'k1':'v1','k2':'v2'}dic2 = dict(k1='v1',k2=' ...