hdu2328 Corporate Identity【string库使用】【暴力】【KMP】
Corporate Identity
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3308 Accepted Submission(s): 1228
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
题意:
给定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】的更多相关文章
- 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
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2328 题目: Corporate Identity Time Limit: 9000/3000 MS (J ...
- [HDU2328]Corporate Identity(后缀数组)
传送门 求 n 个串的字典序最小的最长公共子串. 和 2 个串的处理方法差不多. 把 n 个串拼接在一起,中间连上一个没有出现过的字符防止匹配过界. 求出 height 数组后二分公共子串长度给后缀数 ...
- POJ 题目3450 Corporate Identity(KMP 暴力)
Corporate Identity Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5493 Accepted: 201 ...
- (KMP 暴力)Corporate Identity -- hdu -- 2328
http://acm.hdu.edu.cn/showproblem.php?pid=2328 Corporate Identity Time Limit: 9000/3000 MS (Java/Oth ...
- 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 ...
- N - Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
随机推荐
- 访问 Google
对于一个技术人员访问Google是何其的重要呀? 一下收集了一些访问的连接,不愿意使用VPS的同学可以使用下: 非原版: Glgoo:http://www.glgoo.com/九尾搜索:http:// ...
- Window开启上帝模式
所谓的上帝模式就是所有功能在一个文件下,方便.快捷地操作! 01.新建一个文件夹 02.重命名文件夹 文件夹重命名为“GodMode.{ED7BA470-8E54-465E-825C-99712043 ...
- (原)GAN之pix2pix
转载请注明出处: https://www.cnblogs.com/darkknightzh/p/9175281.html 论文: Image-to-Image Translation with Con ...
- SNF快速开发平台MVC-表格单元格合并组件
1. 表格单元格合并组件 1.1. 效果展示 1.1.1. 页面展现表格合并单元格 图 4.1 1.1.2. 导出excel合并单元格 图 4.2 1.2. 调用说 ...
- React Native for Android应用名及图标修改
应用开发完了,总不能顶着MyProject和小机器人图标就发布了吧?在发布之前,有多处需要修改的地方.今天我们来全面的看一下 应用ID 俗称PackageName,或APP ID.注意,在gradle ...
- [ci]jenkins-slave-ssh docker容器化-自动注入key
jenkins server 再启动slave时候,动态的注入sshkey 只要slave有ssh+jdk即可.无需事先预置用户名密码给slave. 配置 inject ssh key 配置项目 执行 ...
- 扩展layui中的自带字体图标
项目中,虽然layui的字体图标库中已经有了1000多个图标了,但是也有时候不能满足我们自定义图标的需求,所以需要进行自定义,具体步骤如下: 1.在iconfont上找到自己喜欢的图标,也可以上传ui ...
- TCP/IP模型及OSI七层参考模型各层的功能和主要协议
注:网络体系结构是分层的体系结构,学术派标准OSI参考模型有七层,而工业标准TCP/IP模型有四层.后者成为了事实上的标准,在介绍时通常分为5层来叙述但应注意TCP/IP模型实际上只有四层. 1.TC ...
- Qt库版查询
1 背景 在为嵌入式产品开发Qt应用时,开发所使用的Qt库要和嵌入式系统所支持的Qt库版本一致,否则开发的App无法正确运行.那么,如何查询一个嵌入式系统中所安装Qt库的版本呢?下面将进行一些总结. ...
- elasticsearch client 为空 错误信息:java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor
错误信息:java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor() ...