Blue Jeans
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions:21746   Accepted: 9653

Description

The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was populated.

As an IBM researcher, you have been tasked with writing a program that will find commonalities amongst given snippets of DNA that can be correlated with individual survey information to identify new genetic markers.

A DNA base sequence is noted by listing the nitrogen bases in the order in which they are found in the molecule. There are four bases: adenine (A), thymine (T), guanine (G), and cytosine (C). A 6-base DNA sequence could be represented as TAGACC.

Given a set of DNA base sequences, determine the longest series of bases that occurs in all of the sequences.

Input

Input to this problem will begin with a line containing a single integer n indicating the number of datasets. Each dataset consists of the following components:

  • A single positive integer m (2 <= m <= 10) indicating the number of base sequences in this dataset.
  • m lines each containing a single base sequence consisting of 60 bases.

Output

For each dataset in the input, output the longest base subsequence common to all of the given base sequences. If the longest common subsequence is less than three bases in length, display the string "no significant commonalities" instead. If multiple subsequences of the same longest length exist, output only the subsequence that comes first in alphabetical order.

Sample Input

3
2
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
3
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
3
CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

Sample Output

no significant commonalities
AGATAC
CATCATCAT

Source

题意:

给定$m$个场长度为$60$的字符串,问他们的最长公共子串。

思路:

因为$m$和长度都很小,所以可以暴力枚举一个串的所有子串,$KMP$进行匹配。

等之后【后缀数组】刷熟练一点了再用后缀数组做一次。奇怪的是hdu2328明明是一样的题意,怎么就总是WA

 #include<iostream>
//#include<bits/stdc++.h>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<climits>
#include<map>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
#define pi 3.1415926535
#define inf 0x3f3f3f3f const int maxn = ;
int n, m;
char str[][maxn];
int nxt[maxn]; void getnxt(char *s)
{
int len = strlen(s);
nxt[] = -;
int k = -;
int j = ;
while(j < len){
if(k == - || s[j] == s[k]){
++k;++j;
if(s[j] != s[k]){
nxt[j] = k;
}
else{
nxt[j] = nxt[k];
}
}
else{
k = nxt[k];
}
}
} bool kmp(char *s, char *t)
{
getnxt(s);
int slen = strlen(s), tlen = strlen(t);
int i = , j = ;
while(i < slen && j < tlen){
if(j == - || s[i] == t[j]){
j++;
i++;
}
else{
j = nxt[j];
}
}
if(j == tlen){
return true;
}
else{
return false;
}
} int main()
{
scanf("%d", &n);
while(n--){
scanf("%d", &m);
for(int i = ; i < m; i++){
scanf("%s", str[i]);
} char ans[maxn];
int anslen = -;
for(int i = ; i < ; i++){
for(int j = i; j < ; j++){
char t[maxn];
memcpy(t, str[] + i, j - i + );
t[j - i + ] = '\0';
bool flag = true;
for(int k = ; k < m; k++){
if(!kmp(str[k], t)){
flag = false;
break;
}
}
if(flag){
if(j - i + > anslen){
anslen = j - i + ;
strcpy(ans, t);
}
else if(j - i + == anslen){
if(strcmp(ans, t) > ){
strcpy(ans, t);
}
}
}
else{
break;
}
}
} if(anslen < ){
printf("no significant commonalities\n");
}
else{
//cout<<ans<<endl;
printf("%s\n", ans);
} }
return ;
}

poj3080 Blue Jeans【KMP】【暴力】的更多相关文章

  1. POJ3080 - Blue Jeans(KMP+二分)

    题目大意 求N个字符串的最长公共字串 题解 和POJ1226做法一样...注意是字典序最小的...WA了一次 代码: #include <iostream> #include <cs ...

  2. POJ3080 Blue Jeans —— 暴力枚举 + KMP / strstr()

    题目链接:https://vjudge.net/problem/POJ-3080 Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total ...

  3. POJ3080——Blue Jeans(暴力+字符串匹配)

    Blue Jeans DescriptionThe Genographic Project is a research partnership between IBM and The National ...

  4. POJ 3080 Blue Jeans(Java暴力)

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

  5. kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans

    The Genographic Project is a research partnership between IBM and The National Geographic Society th ...

  6. poj3080 Blue Jeans(暴枚+kmp)

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

  7. POJ3080 Blue Jeans 题解 KMP算法

    题目链接:http://poj.org/problem?id=3080 题目大意:给你N个长度为60的字符串(N<=10),求他们的最长公共子串(长度>=3). 题目分析:KMP字符串匹配 ...

  8. POJ-3080-Blue jeans(KMP, 暴力)

    链接: https://vjudge.net/problem/POJ-3080#author=alexandleo 题意: 给你一些字符串,让你找出最长的公共子串. 思路: 暴力枚举第一个串的子串,挨 ...

  9. Blue Jeans---poj3080(kmp+暴力求子串)

    题目链接:http://poj.org/problem?id=3080 题意就是求n个长度为60的串中求最长公共子序列(长度>=3):如果有多个输出字典序最小的: 我们可以暴力求出第一个串的所有 ...

随机推荐

  1. ERROR: Field * doesn't have a default value

    ERROR: Field 'status' doesn't have a default value 今天做项目,在插入数据时出现了这个从没遇到的异常,看了98%的异常分析都是针对组件id出现了类似的 ...

  2. mysql数据库分区功能及实例详解

    分区听起来怎么感觉是硬盘呀,对没错除了硬盘可以分区数据库现在也支持分区了,分区可以解决大数据量的处理问题,下面一起来看一个mysql数据库分区功能及实例详解   一,什么是数据库分区 前段时间写过一篇 ...

  3. 基于mindwave脑电波进行疲劳检测算法的设计(2)

    上文讲到的是保证硬件的接通.接下来是用C语言在它提供的API接口进行连接. 在网盘中下载MindSet Development Tools这个开发包.这个目录下MindSet Development ...

  4. 11gr2 RAC安装INS-35354问题一例

    转自:http://www.askmaclean.com/archives/11gr2-rac安装ins-35354问题一例.html 今天在安装一套11.2.0.2 RAC数据库时出现了INS-35 ...

  5. Redis之AOF重写及其实现原理

    Reference: https://blog.csdn.net/hezhiqiang1314/article/details/69396887 AOF 重写AOF 持久化是通过保存被执行的写命令来记 ...

  6. 【emWin】例程十三:字库放到外部存储器

    介绍: 本例将字库文件放到SD卡中,通过读取SD卡中的字库文件在液晶上显示文字.   实验指导书及代码包下载: 链接:http://pan.baidu.com/s/1bo0yTLd 密码:i4sm   ...

  7. opencv 基本使用

    1.下载opencv库 https://opencv.org/ 下载后文件: 双击提取文件到指定路径: * 下载winpack版本可以省去自己编译的步骤,下载后无需安装双击可以直接提取文件到指定目录: ...

  8. java 全组合 与全排列

    一.全组合 public static void Combination( ) { /*基本思路:求全组合,则假设原有元素n个,则最终组合结果是2^n个.原因是: * 用位操作方法:假设元素原本有:a ...

  9. Solr中的q与fq参数的区别

    转自:搜索系统5:Solr中的q与fq参数的区别在那儿 1.对结果排序有影响 今天遇到一个问题,把相同的参数比如name:张三,放到q与fq,两者返回的结果完全不一样. 经过debug发现,原因是这两 ...

  10. Linux systemd limits

    https://www.cnblogs.com/IMxY/p/8941022.html limits 关于Centos 7 / RHEL 7 中的limits要了解以下几点: CentOS 7 / R ...