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. 在laravel中使用QrCode包生成二维码

    http://laravelacademy.org/post/2605.html 一切都是按照文档上的说明操作,没有问题

  2. Navicat for MySQL使用手记(下)--实现自动备份数据库

    五.备份和还原MySQL数据库 在数据库的管理中,备份和还原是必须做认真做的事情,如果疏忽或者做粗糙了,那么一旦数据库故障后果不堪设想,所以Navicat同样也有备份和还原的功能,相比较创建功能,其备 ...

  3. 实战 TestNG 监听器

    TestNG 是一个开源的自动化测试框架,其灵感来自 JUnit 和 NUnit,但它引入了一些新功能,使其功能更强大,更易于使用.TestNG 的设计目标是能够被用于进行各种类型测试:单元测试.功能 ...

  4. verilog HDL 编码风格

    1.有意义且有效的名字. 2.同一信号在不同层次应该保持一致. 3.添加有意义的后缀,使信号的有效性更加明确. 4.模块输出寄存器化,使得输出的驱动强度和输入延时是可以预测的. 5.使用括号表明优先级 ...

  5. shulti模块简述

    #-*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import shutil shutil.copyfileobj('D:\\3. ...

  6. 爬取github上流行的python项目

    # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import requests from pyquery import PyQ ...

  7. Linux quota命令参数及用法详解---Linux磁盘配额限制设置和查看命令

    功能说明:显示磁盘已使用的空间与限制. 语 法:quota [-quvV][用户名称...] 或 quota [-gqvV][群组名称...] 补充说明:执行quota指令,可查询磁盘空间的限制,并得 ...

  8. mysql忘记root密码的处理方法

    在linux下,如果忘记了mysql中root用户的密码可以采用以下办法解决. 1. 修改my.cnf,加入skip-grant-tables 修改mysql的配置文件my.cnf,在[mysqld] ...

  9. .net 连接ORACLE中文显示乱码解决方案

    FYI由于历史的原因,早期的oracle没有中文字符集(如oracle6.oracle7.oracle7.1),但有的用户从那时起就使用数据库了, 并用US7ASCII字符集存储了中文,或是有的用户在 ...

  10. Deep Learning(深度学习)学习笔记整理系列

    http://blog.csdn.net/zouxy09/article/details/8775360 http://blog.csdn.net/zouxy09/article/details/87 ...