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 ...
随机推荐
- 转 qInstallMsgHandler实现日志输出
#include <QtDebug> #include <QFile> #include <QTextStream> #define _TIME_ qPrintab ...
- android的activity被杀死后如何重启
最近公司的大屏展示机器人上的程序运行时间长了,比如五天,十天会出现偶尔的崩溃,查日志可能是内存溢出或者是ndk层的错误,这种错误一时也不太好查找,但是产品那边有个要求就是程序退出了一定要能重启,能抓日 ...
- ajax之async属性
Ajax请求中的async:false/true的作用 官方的解释是:http://api.jquery.com/jQuery.ajax/ async Boolean Default: true By ...
- 6.翻译系列:EF 6 Code-First中数据库初始化策略(EF 6 Code-First系列)
原文链接:http://www.entityframeworktutorial.net/code-first/database-initialization-strategy-in-code-firs ...
- PHP —— 识别运算符实现逻辑比较
最近遇到一个功能的开发,大致意思就是根据用户输入的条件,进行相关的比较操作.本来打算使用用户选择运算符的方式,但是后来结合项目实际,发现需要使用用户输入的自定义运算比较现实一点.大致意思就是: 1.用 ...
- 物联网架构成长之路(3)-EMQ消息服务器了解
1. 了解 物联网最基础的就是通信了.通信协议,物联网协议好像有那么几个,以前各个协议都有优劣,最近一段时间,好像各大厂商都采用MQTT协议,所以我也不例外,不搞特殊,采用MQTT协议,选定了协议,接 ...
- git 创建标签
在Git中打标签非常简单,首先,切换到需要打标签的分支上: $ git branch * dev master $ git checkout master Switched to branch 'ma ...
- python bottle框架 解决跨域问题的正确方式
经查询,网上有几种说法 https://www.cnblogs.com/EmptyFS/p/6138923.html 我首先查到的就是这个,我采用了文中所说的修改源码的方式, 但是经测试发现,修改源码 ...
- too many open files
压测遇到这个问题,每次都查,记录一下: 系统分配文件数太少,临时修改方案: ulimit -n 2048 永久配置: vim /etc/security/limits.conf 底部配置: # End ...
- MAC OS查看端口占用情况及杀死进程
终端命令 sudo lsof -i :9000 COMMAND PID USER FD TYPE DEVICE ...