Blue Jeans
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 20695   Accepted: 9167

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

#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<iostream>
#define nb main
#define i6g3y int
using namespace std; const int maxn = 100+10;
const int INF = 0x3f3f3f3f; using namespace std; string s[100]; int mynext[maxn];
void getnext(string a,int len){
int i,j;
j=mynext[0]=-1;
i=0;
while(i<len){
while(-1!=j&&a[i]!=a[j])j=mynext[j];
mynext[++i]=++j;
}
}
bool kmpcount(string a,int len1,string b,int len2){
int i,j;
i=j=0;
while(i<len2){
while(-1!=j&&a[j]!=b[i])j=mynext[j];
i++;j++;
if(j>=len1){
return true;
}
}
return false;
}
bool mycmp(string a,string b){
if(a.length()>b.length())return true;
else return b.compare(a);
}
i6g3y nb()
{
int t;
std::ios::sync_with_stdio(false);
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=0;i<n;i++)cin>>s[i];
string best="";
bool flag=false;//标志这个长度的这个串有没有匹配
bool Allflag=false;//标志这个长度有没有匹配
int i;
for(i=1;i<=60;i++){//长度
Allflag=false; //假设这个长度不可以
for(int first=0;first<60-i+1;first++){//起点
flag=true;//假设这个串可以
string test=s[0].substr(first,i);//模式串 getnext(test,i);//求next
for(int g=1;g<n;g++){
if(!kmpcount(test,i,s[g],60)){//如果有一个不匹配
flag=false;
break;
}
}
if(flag){//如果匹配
//cout<<"test "<<test;
//cout<<" 可以匹配"<<endl;
Allflag=true;
if(mycmp(test,best)){
best=test;
}
}
}
if(!Allflag){
break;
}
}
if(i<3)cout<<"no significant commonalities"<<endl;
else cout<<best<<endl;
}
return 0;
}

  

POJ 3080-Blue Jeans【kmp,字符串剪接】的更多相关文章

  1. poj 3080 Blue Jeans【字符串处理+ 亮点是:字符串函数的使用】

    题目:http://poj.org/problem?id=3080 Sample Input 3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCA ...

  2. POJ 3080 Blue Jeans (求最长公共字符串)

    POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...

  3. POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)

    Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20966   Accepted: 9279 Descr ...

  4. POJ 3080 Blue Jeans (字符串处理暴力枚举)

    Blue Jeans  Time Limit: 1000MS        Memory Limit: 65536K Total Submissions: 21078        Accepted: ...

  5. poj 3080 Blue Jeans 解题报告

    题目链接:http://poj.org/problem?id=3080 该题属于字符串处理中的串模式匹配问题.题目要求我们:给出一个DNA碱基序列,输出最长的相同的碱基子序列.(保证在所有的序列中都有 ...

  6. POJ 3080 Blue Jeans(Java暴力)

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

  7. poj 3080 Blue Jeans

    点击打开链接 Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10243   Accepted: 434 ...

  8. POJ 3080 Blue Jeans、POJ 3461 Oulipo——KMP应用

    题目:POJ3080 http://poj.org/problem?id=3080 题意:对于输入的文本串,输出最长的公共子串,如果长度相同,输出字典序最小的. 这题数据量很小,用暴力也是16ms,用 ...

  9. poj 3080 Blue Jeans (暴力枚举子串+kmp)

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

  10. POJ - 3080 Blue Jeans 【KMP+暴力】(最大公共字串)

    <题目链接> 题目大意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 限制条件: 1.  最长公共串长度小于3输出   no significant co ...

随机推荐

  1. script async和defer

    1.没有async和defer,html解析时遇到script标签,会先去下载js文件,文件加载完成立即执行,执行完了再开始解析后面的html,是一个顺序流的过程 2.async,加载和渲染后续文档元 ...

  2. 关于ADB push 出现failed to copy 'D:\file.xtxt' to '/system/temp/' : Read-only file system 的报错信息解决办法

    首先使用USB连接电脑与小机,然后安装adb相应的驱动,这是第一步,也是必须要做的. 进入doc系统后,敲入adb shell  可以进入linux命令行状态,说明adb可以使用了. 回到标题,我们现 ...

  3. 验证表单的js代码段

     JS常用功能 转载自:http://blog.csdn.net/kalision/article/details/12516103 引用js文件: <script src="js/d ...

  4. Python全栈工程师(列表、拷贝)

    ParisGabriel     感谢 大家的支持  你们的阅读评价就是我最好的更新动力  我会坚持吧排版做的越来越好      每天坚持 一天一篇 点个订阅吧  灰常感谢    当个死粉也阔以 Py ...

  5. 孤荷凌寒自学python第四十一天python的线程同步之Event对象

     孤荷凌寒自学python第四十一天python的线程同步之Event对象 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 鉴于Lock锁与RLock锁均宣告没有完全完成同步文件操作的问题,于 ...

  6. Mac 电脑鼠标和触摸板滚动方向不一致的问题【已解决】

    当我们使用鼠标连接到 MacBook 时,会发现无论怎么设置,鼠标和触摸板的滚动方向都是相反的,导致不能同时使用鼠标和触摸板 解决方法: 我安装了下面的程序,它只允许您反转鼠标的滚动行为: Scrol ...

  7. 原始套接字--traceroute

    traceroute, 也就是 trace route,跟踪路由.这个程序最早是Van Jacobson实现的.源码在网上可以找到,不过我还没有去找.是IP路由过程中对数据包TTL(Time to L ...

  8. 冒泡排序js

    //    冒泡排序     var a = [1,3,2,4,5,3,2,1,4,6,7,7,6,6];     var b =[];     for(var i=0;i<a.length;i ...

  9. HDU 4101 Ali and Baba (思路好题)

    与其说这是个博弈,倒不如说是个搜索.这题思路不错,感觉很难把情况考虑周全. 在地图外围填充一圈0,两次BFS,第一次从-1点出发,把从-1到达的0点以及包围0的那一圈石头标记出来.如下图: 1 1 1 ...

  10. Android记事本05

    昨天: intentFilter 今天: URL和logcat 问题: ADK更新后无法打开布局文件.xml