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
题意:有m个串(m<=10)求所有串的最长连续公共子串,如有多个解输出字典序最小的
题解:按长度倒着暴枚出第一串的所有子串,用kmp查找这个子串是不是在所有其他串中即可
但是
说好的只有"ACGT"四个字母呢?!
说好的只有长度为六十的串呢?!
人与人之间基本的信任呢?! 代码如下:
#include<queue>
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define hi puts("hi!");
using namespace std; int m,n,cnt;
string ans,s[],s1[]; struct kmp
{
string ss,sss;
int ans,nxt[]; void getfill()
{
memset(nxt,,sizeof(nxt));
for(int j=;j<sss.size();j++)
{
int k=nxt[j];
while(k&&sss[j]!=sss[k])
{
k=nxt[k];
}
nxt[j+]=(sss[j]==sss[k])?k+:;
}
} void find()
{
ans=;
getfill();
int k=;
for(int j=;j<ss.size();j++)
{
while(k&&ss[j]!=sss[k])
{
k=nxt[k];
}
if(ss[j]==sss[k])
{
k++;
}
if(k==sss.size())
{
ans=;
}
}
} }k; int main()
{
// freopen("1.out","w",stdout);
scanf("%d",&m);
while(m--)
{
int flag=,flag1=;
cnt=;
scanf("%d\n",&n);
for(int i=;i<=n;i++)
{
cin>>s[i];
}
int len=s[].size();
for(int i=len;i>=;i--)
{
if(i<)
{
puts("no significant commonalities");
break;
}
for(int l=;l<=len-i;l++)
{
string sub=s[].substr(l,i);
flag=;
for(int w=;w<=n;w++)
{
k.ss=s[w];
k.sss=sub;
k.find();
flag=min(flag,k.ans);
}
if(flag)
{
s1[++cnt]=sub;
flag1=;
}
}
if(flag1)
{
string ans1=s1[];
for(int ha=;ha<=cnt;ha++)
{
if(ans1.compare(s1[ha])==)
{
ans1=s1[ha];
}
}
cout<<ans1<<endl;
break;
}
}
}
}



poj3080 Blue Jeans(暴枚+kmp)的更多相关文章

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

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

  2. poj3080 Blue Jeans【KMP】【暴力】

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

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

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

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

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

  5. POJ3080 Blue Jeans 题解 KMP算法

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

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

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

  7. 【poj 3080】Blue Jeans(字符串--KMP+暴力枚举+剪枝)

    题意:求n个串的字典序最小的最长公共子串. 解法:枚举第一个串的子串,与剩下的n-1个串KMP匹配,判断是否有这样的公共子串.从大长度开始枚举,找到了就break挺快的.而且KMP的作用就是匹配子串, ...

  8. POJ3080 Blue Jeans

    题目链接. 题目大意: 给定n个字符串,找出最长相同且长度大于3的子串,如果存在多个,找出字典序最小的. 分析: 直接枚举(暴搜). 对于s[0]的每一个子串,判断是否在其它n-1个字符串中都存在. ...

  9. (字符串 KMP)Blue Jeans -- POJ -- 3080:

    链接: http://poj.org/problem?id=3080 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#probl ...

随机推荐

  1. python学习之logging

    学习地址:http://blog.csdn.net/zyz511919766/article/details/25136485 首先如果我们想简要的打印出日志,可以: import logging l ...

  2. nginx.conf解读

    通常我们需要配置nginx.conf或者配置子项目的配置文件,那么我们需要解读它里面每一个参数的意义,就来个范例解读吧(有中午注释) #运行用户 user www-data; #启动进程,通常设置成和 ...

  3. layui与layer同时引入冲突的问题

    之前在项目中只有用layer,但是后来有用到了layui,结果发现同时引入这两个东东 会出现冲突的问题 导致代码运行不正常 后来网上找到了解决办法: 学习源头:http://fly.layui.com ...

  4. BroadcastReceiver用法

    动态注册广播接收器 1.创建一个Receiver继承BroadcastReceiver,并重写onReceiver() 2.在Activity的OnCreate()中添加广播接收器想要接收的actio ...

  5. Activity小技巧

    随时随地退出程序 新建一个结合类对所有活动进行管理. public class ActivityCollector{ public static List<Activity> activi ...

  6. Java:Java 清单

    ylbtech-Java:Java 清单 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylb ...

  7. 【原创】深入理解Docker容器和镜像 -- 分析了docker的命令含义

    10张图带你深入理解Docker容器和镜像 镜像(Image)就是一堆只读层(read-only layer)的统一视角 要点:容器 = 镜像 + 读写层.并且容器的定义并没有提及是否要运行容器. 一 ...

  8. Py修行路 python基础 (十)装饰器

    装饰器 一.定义 装饰器:顾名思义,就是对某个东西起到装饰修饰的功能. python中的装饰器,其本质上就是一个python函数,它可以让其他函数在不需要任何代码变动的前提下增加额外功能.通俗理解就是 ...

  9. js中的Generators函数

    js中的Generators函数 generator一般操作 generator函数的作用就是函数体分段执行,yield表示分隔点 function *test() { console.log(1); ...

  10. ssh secure shell 乱码问题

    1.  执行命令 locale 查看,出现如下: [root@catxjd ~]# locale LANG=zh_CN.GB2312 LC_CTYPE="zh_CN.GB2312" ...