题目网址:http://poj.org/problem?id=3080

思路:

以第一个DNA序列s为参考序列,开始做以下的操作。

1.将一个字母s[i]作为匹配串。(i为当前遍历到的下标)

2.遍历所有序列,看是否是所有序列的公共子串

3.是所有序列的子串的话,再往后增加一个字母,组成一个长度len+1的匹配串(设原先匹配串长度为len),重复步骤2

4.不是所有序列的子串的话,i=len+i;判断len是否大于3,是的话保存子串。len=0;重复步骤1。(为什么 i=len+i呢?因为len+i都是已经匹配到的,则从i+1 到 i+len 的匹配数会分别比当前匹配数小1…len-1 可以自己推一遍为什么)

5.对结果排序,找出最长,若长度相同的情况下,字典序最小的子串

代码:

 #include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int n;
char s[][];
char temp[];
vector<string>v;
map<string,int>mp;
bool cmp(string x,string y){
if(x.length()==y.length()){
int i=;
while (x[i]==y[i]) i++;
return x[i]<y[i];
}
return x.length()>y.length();
}
int main(){
int t;
scanf("%d",&t);
while (t--) {
mp.clear();
v.clear();
scanf("%d",&n);
for (int i=; i<n; i++) scanf("%s",s[i]);
for (int i=; i<; i++) {
int ok=,l=;
string str="";
memset(temp, , sizeof(temp));
temp[]=s[][i];
while(l+i< && ok){
for (int i=; i<n; i++) {
if(strstr(s[i], temp)==NULL){
ok=;
break;
}
}
if(ok){
str+=s[][i+l];
l++;
temp[l]=s[][i+l];
}
}
if(mp[str]== && str.size()>=){
v.push_back(str);
mp[str]=;
i=l+i;
}
}
sort(v.begin(), v.end(), cmp);
if (v.size()>) cout<<v[]<<endl;
else printf("no significant commonalities\n");
}
}

POJ 3080 Blue Jeans(串)的更多相关文章

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

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

  2. POJ 3080 Blue Jeans(Java暴力)

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

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

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

  4. poj 3080 Blue Jeans

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

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

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

  6. POJ - 3080 Blue Jeans 【KMP+暴力】(最大公共字串)

    <题目链接> 题目大意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 限制条件: 1.  最长公共串长度小于3输出   no significant co ...

  7. poj 3080 Blue Jeans 解题报告

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

  8. POJ 3080 Blue Jeans(后缀数组+二分答案)

    [题目链接] http://poj.org/problem?id=3080 [题目大意] 求k个串的最长公共子串,如果存在多个则输出字典序最小,如果长度小于3则判断查找失败. [题解] 将所有字符串通 ...

  9. POJ 3080 Blue Jeans 后缀数组, 高度数组 难度:1

    题目 http://poj.org/problem?id=3080 题意 有m个(2<=m<=10)不包含空格的字符串,长度为60个字符,求所有字符串中都出现过的最长公共子序列,若该子序列 ...

随机推荐

  1. centos7下mysql 用户管理和权限设置

    1.进入mysql命令行,输入root及密码[root@localhost ~]# mysql -u root -pEnter password: Welcome to the MySQL monit ...

  2. 《Java7并发编程实战手册》读书笔记

    一.线程管理 1.线程的创建和运行 创建线程的2种方式: 继承Thread类,并覆盖run()方法 创建一个实现Runnable接口的类.使用带参数的Thread构造器来创建Thread对象 每个Ja ...

  3. ORA-08102异常重现及恢复

    现象: 在表上面新建主键报ORA-08102的异常: SQL> alter table t add primary key(id); alter table t add primary key( ...

  4. 单元测试框架Uinttest一文详解

    一谈及unittest,大家都知道,unittest是Python中自带的单元测试框架,它里面封装好了一些校验返回的结果方法和一些用例执行前的初始化操作.unittest单元测试框架不仅可以适用于单元 ...

  5. java Swing 界面化查询数据库表

    两天从0基础写的.没有按钮对话框功能,只是简单的实现. 当然代码上有很多需要优化的,基本需要重写哈哈哈.但是我怕以后有需要所以还是存一下好了.<把RS结果集,放vector里面,用vector构 ...

  6. Spring boot 官网学习笔记 - Spring Boot CLI 入门案例

    安装CLI https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.1.1.RELEASE/spring-b ...

  7. Spring Security 梳理 - DelegatingFilterProxy

    可能你会觉得奇怪,我们在web应用中使用Spring Security时只在web.xml文件中定义了如下这样一个Filter,为什么你会说是一系列的Filter呢?    <filter> ...

  8. 在vue的mounted下使用setInterval的误区

    1. vue对象的生命周期 1). 初始化显示(只执行一次) * beforeCreate() * created() * beforeMount() * mounted() 2). 更新状态(可执行 ...

  9. 整理基础的CentOS常用命令

    如何知道apache装在哪里? which httpd 1.查看系统使用端口并释放端口 [root@my_nn_01 WEB-INF]# lsof -w -n -i tcp:80 COMMAND    ...

  10. 使用 chart 部署 skywalking

    使用 chart 部署 skywalking 本文主要讲述的是如何使用 Helm Charts 将 SkyWalking 部署到 Kubernetes 集群中,相关文档可以参考skywalking-k ...