<题目链接>

题目大意:

就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10

限制条件:

1、  最长公共串长度小于3输出   no significant commonalities

2、  若出现等长的最长的子串,则输出字典序最小的串

解题分析:

将第一个字串的所有子串枚举出来,然后用KMP快速判断该子串是否在所有主串中出现,如果都出现过,那么就按该子串的长度和字典序,不断更新答案,直到得到最终的最优解。

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=+;
const int M=+; string s[N];
int nxt[M]; void getnext(string str,int len){
int i=,j=-;
nxt[]=-;
while(i<len){
if(j==-||str[i]==str[j])
nxt[++i]=++j;
else j=nxt[j];
}
}
bool kmp(string s1,int len1,string s2,int len2){
int i=,j=;
while(i<len1){
if(j==-||s1[i]==s2[j])
++i,++j;
else j=nxt[j];
if(j==len2)return true;
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int T,n;
cin>>T;
while(T--){
cin>>n;
for(int i=;i<n;i++)cin>>s[i];
string ans="";
for(int i=;i<s[].size();i++) //起点
{
for(int j=;i+j<=s[].size();j++) //长度
{
string res=s[].substr(i,j);
getnext(res,res.size());
bool flag=;
for(int k=;k<n;k++)
if(!kmp(s[k],s[k].size(),res,res.size()))
flag=;
if(!flag)
{
if(ans.size()<res.size())ans=res; //优先长度更长的公共子串
else if(ans.size()==res.size())ans=min(ans,res); //长度相同,按字典序排序
}
}
}
if(ans.size()<)cout<<"no significant commonalities"<<endl;
else cout<<ans<<endl;
}
return ;
}

2018-08-07

POJ - 3080 Blue Jeans 【KMP+暴力】(最大公共字串)的更多相关文章

  1. POJ 3080 Blue Jeans (求最长公共字符串)

    POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...

  2. POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)

    Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20966   Accepted: 9279 Descr ...

  3. POJ 3080 Blue Jeans(Java暴力)

    Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...

  4. poj 3080 Blue Jeans 解题报告

    题目链接:http://poj.org/problem?id=3080 该题属于字符串处理中的串模式匹配问题.题目要求我们:给出一个DNA碱基序列,输出最长的相同的碱基子序列.(保证在所有的序列中都有 ...

  5. POJ 3080 Blue Jeans (多个字符串的最长公共序列,暴力比较)

    题意:给出m个字符串,找出其中的最长公共子序列,如果相同长度的有多个,输出按字母排序中的第一个. 思路:数据小,因此枚举第一个字符串的所有子字符串s,再一个个比较,是否为其它字符串的字串.判断是否为字 ...

  6. POJ 3080 Blue Jeans (字符串处理暴力枚举)

    Blue Jeans  Time Limit: 1000MS        Memory Limit: 65536K Total Submissions: 21078        Accepted: ...

  7. poj 3080 Blue Jeans

    点击打开链接 Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10243   Accepted: 434 ...

  8. 【POJ 3080 Blue Jeans】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...

  9. poj 3080 Blue Jeans (暴力枚举子串+kmp)

    Description The Genographic Project is a research partnership between IBM and The National Geographi ...

随机推荐

  1. 第16月第17天 contentMode

    1. self.contentMode = UIViewContentModeScaleAspectFill; self.clipsToBounds = YES; http://blog.csdn.n ...

  2. Sqoop异常:Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject

    18/12/07 01:09:03 INFO mapreduce.ImportJobBase: Beginning import of staffException in thread "m ...

  3. 五校联考 running (欧拉函数)

    题面 \(solution:\) 讲真吧,这道题真的出得,嗯,太恐怖了.考场上这道题真的把我看懵了,这道题以前是见过的,但欧拉函数?我学过吗?一道容斥都要超时的题目,我都要为我自己点根香了,拿着gcd ...

  4. Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV

    今天在使用JSP,引入<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> ...

  5. Android APP常见的5类内存泄露及解决方法

    1.static变量引起的内存泄漏 因为static变量的生命周期是在类加载时开始 类卸载时结束,也就是说static变量是在程序进程死亡时才释放,如果在static变量中 引用了Activity 那 ...

  6. 2018-2019-2 网络对抗技术 20165230 Exp5 MSF基础应用

    目录 1.实验内容 2.基础问题回答 3.实验内容 任务一:一个主动攻击实践 漏洞MS08_067(成功) 任务二:一个针对浏览器的攻击 ms11_050(成功) ms14_064(成功) 任务三:一 ...

  7. Jetson tk1 安装 Intel 7260 无线网卡驱动

    Jseton TK1上没有集成的无线网卡,开发板上有一个mini pci-e接口,可以插入Intel 7260这款继承了wifi和蓝牙功能的无线网卡: 该网卡实物如下图,在淘宝和Amazon上都可以买 ...

  8. OpenCV:Debug和Release模式 && 静态和动态编译

    1.Release和Debug的区别 Release版称为发行版,Debug版称为调试版. Debug中可以单步执行.跟踪等功能,但生成的可执行文件比较大,代码运行速度较慢.Release版运行速度较 ...

  9. kmalloc vmalloc kzalloc malloc 和 get_free_page()【转】

    转自:http://blog.csdn.net/hbhhww/article/details/7236695 kmalloc vmalloc kzalloc get_free_page()是内核空间申 ...

  10. 百度AI—人脸在线比对

    首先访问百度AI网站:https://cloud.baidu.com/,按照下图的指示点开到应用管理的页面. 穿件完成之后到管理中可以查看到对应的 添加工具类: using System; using ...