Corporate Identity

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

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

题意:

给定n个串,问他们的最长公共子串是什么。

思路:

因为串长是200,串的个数是4000。暴力枚举一个串的所有子串的话是200 * 200.

枚举子串和其他串匹配,统计个数【暴力这么过去了其实是有点虚的。】

尝试用了一下string中的substr和find函数。

substr(j,len)表示从s[j]开始取len长度的子串(包括j)。这题的样例也 太烂了,怎么都过得去。

当然这题应该也能用后缀数组做。

 //#include<bits/stdc++>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdlib.h> #define LL long long
#define ull unsigned long long
#define inf 0x3f3f3f3f using namespace std; int n;
const int maxn = ;
const int maxlen = ;
string s[maxn]; int main()
{
while(scanf("%d", &n) && n){
for(int i = ; i < n; i++){
cin >> s[i];
}
int len = s[].length();
int ans = ;
string ansch;
for(int i = ; i <= len; i++){
for(int j = ; j <= len - i; j++){
int tot = ;
for(int k = ; k < n; k++){
if(s[k].find(s[].substr(j, i)) == string::npos){
break;
}
else tot++;
}
if(tot == n - ){
if(i > ans || i == ans && s[].substr(j, i) < ansch){
ansch = s[].substr(j, i);
ans = i;
}
}
}
} if(ansch != ""){
cout<<ansch<<endl;
}
else{
cout<<"IDENTITY LOST\n";
}
}
}

hdu2328 Corporate Identity【string库使用】【暴力】【KMP】的更多相关文章

  1. hdu2328 Corporate Identity 扩展KMP

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

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

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

  3. hdu2328 Corporate Identity

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

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

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

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

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

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

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

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

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

  8. hdu 2328 Corporate Identity(kmp)

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

  9. N - Corporate Identity

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

随机推荐

  1. SoapUI Pro Project Solution Collection-XML assert

    in soapui the XML object used here is from  org.w3c.dom package so you need to read this article car ...

  2. 【Android】详解Android 网络操作

    目录结构: contents structure [+] 判断网络 判断是否有网络连接 判断WIFI网络是否可用 判断MOBILE网络是否可用 获取当前网络连接的类型信息 监听网络 获取网络信息需要在 ...

  3. input框触发回车事件

    window.event只能在IE下运行,不能在firefox下运行,这是因为firefox的event只能在事件发生的现场使用.   在firefox里直接调用event对象会报undefined. ...

  4. Android 网络知识必知必会

    目录: 网络分层 TCP 和 UDP 区别 TCP 三次握手以及为什么需要三次握手 UDP 四次挥手以及为什么需要四次挥手 socket 开发相关 Http 是什么 Https 是什么以及和 HTTP ...

  5. GSSAPIAuthentication=no

    GSSAPI ( Generic Security Services Application Programming Interface) 是一套类似Kerberos 5的通用网络安全系统接口.该接口 ...

  6. python requests库使用

    迫不及待了吗?本页内容为如何入门 Requests 提供了很好的指引.其假设你已经安装了 Requests.如果还没有,去安装一节看看吧. 首先,确认一下: Requests 已安装 Requests ...

  7. 【Linux高级驱动】rtc驱动开发

    [1.分层思想] 1.1 rtc-dev.c   //设备接口层,功能:给用户提供接口 subsys_initcall(rtc_init);   , RTC_DEV_MAX, "rtc&qu ...

  8. AI金融知识自学偏量化方向-前提1

    前提: 统计学习(统计分析)和机器学习之间的区别 金融公司采用机器学习技术及招募相关人才要求 第一个问题:  机器学习和统计学都是数据科学的一部分.机器学习中的学习一词表示算法依赖于一些数据(被用作训 ...

  9. JVM 内部原理(六)— Java 字节码基础之一

    JVM 内部原理(六)- Java 字节码基础之一 介绍 版本:Java SE 7 为什么需要了解 Java 字节码? 无论你是一名 Java 开发者.架构师.CxO 还是智能手机的普通用户,Java ...

  10. android开发(49) Android 下拉刷新的实现。使用 SwipeRefreshLayout 代替 pull-to-refesh

    概述 谷歌官方推出了SwipeRefreshLayout 来实现下拉刷新的效果.对比以前我们常用的 pull-to-refesh ,这个方案显得更加的简单方便. 关联项目引用(管理依赖) 在你的 应用 ...