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. 随时查找中位数——pat1057

    http://pat.zju.edu.cn/contests/pat-a-practise/1057 题目的意思是可以在一个可以任意添加于删除整数的集合里随时查找该集合的中位数 每次查找用nlogn的 ...

  2. cxGrid使用汇总3

    32根据单元的值设置样式   解决:procedure   <aForm>.<aColumn>StylesGetContentStyle(         Sender:   ...

  3. laravel 中条件查询 function模式

    当需要条件查找时,可以使用下面的注入方法: //我要预约 yudoc_name yudoc_keshi yudoc_jibing yudoc_hospital 这是需要帅选的条件 public fun ...

  4. Centos7手工安装Kubernetes集群

    安装Kubernetes集群有多种方式,前面介绍了Kubeadm的方式,本文将介绍手工安装的方法. 安装环境有3台Azure上的VM: Hkube01:10.0.1.4 Hkube02:10.0.1. ...

  5. unittest框架,调用函数类 和 调用函数外的 方法

  6. CIDR地址分类

    CIDR(Classless Inter Domain Routing)改进了传统的IPv4地址分类.传统的IP分类将IP地址直接对应为默认的分类,从而将Internet分割为网络.CIDR在路由表中 ...

  7. kali 软件源 包含virtualbox所需头文件

    # deb cdrom:[Debian GNU/Linux 7.0 _Kali_ - Official Snapshot i386 LIVE/INSTALL Binary 20130905-08:50 ...

  8. pymysql简单链接示例

    #!/usr/bin/env python # encoding: utf-8  # Date: 2018/6/24 import pymysql username = input('username ...

  9. 整合多个py文件接口的unittest。suite执行方法

    1.每个接口用例为一个.py文件.内容如下: getAdMakeMoneyList文件: # coding=utf-8import xlrdimport requestsimport unittest ...

  10. 第十九章 MySQL Cluster(待续)

    ··········