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 ...
随机推荐
- Memcache及telnent命令具体解释
1.启动Memcache 经常使用參数 memcached 1.4.3 -p <num> 设置port号(默认不设置为: 11211) -U <num> U ...
- SoapUI Pro Project Solution Collection-access the soapui object
Technorati 标签: Soapui pro,web service,apI Testing
- redis优化配置和redis.conf说明(转)
1. redis.conf 配置参数: #是否作为守护进程运行 daemonize yes #如以后台进程运行,则需指定一个pid,默认为/var/run/redis.pid pidfile redi ...
- SQL 中的多条件查询
在应用程序开发中,多条件查询是个经常遇到的情况,最简单最麻烦的方法是把所有的可能情况都考虑到,但是无疑是繁琐的,而且很容易漏掉可能的情形,下面是SQL语句实现多条件查询的情况 select * fro ...
- 2013-2015 Aaronyang的又一总结,牧童遥指纳尼村
我没有时间去唠叨自己的事,可是你们是我喜欢的人,ay很愿意写给你们分享:去年的万人阅读的总结链接:<没学历的IT人生没那么悲催,献给程序员们> 提前声明:本文不良反应:请自备垃圾桶,准备装 ...
- Nginx 介绍
Nginx 是什么 Nginx ("engine x") 是一个开源的,支持高性能.高并发的 Web 服务和代理服务软件.它是由俄罗斯人 Igor Sysoev 开发的,最初被应用 ...
- hexo + Github Page 0元建立博客攻略
传送门: 5分钟 0元搭建个人独立博客网站(一):https://mp.weixin.qq.com/s/69isJE191WV2gaVbjrwTtw 5分钟 0元搭建个人独立博客网站(二):https ...
- .NET+MVC+ORACLE存储分页查询一前端实现
MemberList.cshtml @{ ViewBag.Title = "用户列表"; Layout = null;} <!DOCTYPE html> & ...
- ios UIButton设置高亮状态下的背景色
一,通过按钮的事件来设置背景色 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - (void)viewDidLoad { [ ...
- Java编程的逻辑 (84) - 反射
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http: ...