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. IaaS vs PaaS vs SaaS

    在云计算的早期阶段,企业面临的最大问题是他们是否应该使用公共云服务.如今,几乎所有的组织都在采用一些公共云服务.更重要的问题是企业应该使用哪种云服务:基础设施即服务(IaaS),平台即服务(PaaS) ...

  2. git常用命令小结

    1.ssh连接方式 公钥生成ssh-keygen -t rsa -C "764432054@qq.com"在用户家目录下的.ssh目录下生成 id_rsa ,id_rsa.pub ...

  3. AJAX验证此ID是否有对应的name

    在表格输入一个ID,然后自动根据ID在数据库中查找是否有对应name 这是javascript部分,利用ajax验证 $(document).ready(function() { $("#c ...

  4. PHP面向对象深入研究之【高级特性】

    静态属性 <?php class StaticExample { static public $aNum = 0; // 静态共有属性 static public function sayHel ...

  5. VMware80端口映射

    目标是外网访问80端口,然后映射到虚拟机的80端口,80映射到80. 1.首先80端口是最常用的端口,要确认主机80端口是否被占用,如果被占用,停止或者修改占用80端口程序. 2.80端口默认防火墙是 ...

  6. 0003-程序流程1之app.js

    index.html中引入各种依赖的文件 由ng-app处开始angular Js的管理 angular.module('App', ['']) .run(function($rootScope,.. ...

  7. [转]C#开发微信公众平台-就这么简单

    本文转自:http://www.it165.net/pro/html/201403/11102.html 写在前面 服务号和订阅号 URL配置 创建菜单 查询.删除菜单 接受消息 发送消息(图文.菜单 ...

  8. 前端学习笔记一:什么是W3C?

    俗话说好记性不如烂笔头,最近在学习前端技术,一些理论性的知识虽然理解,但有时确不能精准的用语言表述出来,那就索性记下来吧,以备以后时常查看: 我们平时说的W3C,其实是World Wide Web C ...

  9. log4j配置文件的手动加载与配置初始化

    一. 本地项目: 初始化log4j的日志配置,指定到src目录下(建议用2)         //1. 本地项目-属性文件配置         PropertyConfigurator.configu ...

  10. web表单disable问题

    Web表单提交之disabled问题 例如,有如下表单 <form id="inputForm" action="shorttermrental.action&qu ...