博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3080 KMP
阅读量:7040 次
发布时间:2019-06-28

本文共 3521 字,大约阅读时间需要 11 分钟。

Blue Jeans
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 11564   Accepted: 4969

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

32GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAGATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAAGATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA3CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

Sample Output

no significant commonalitiesAGATACCATCATCAT

 

 

题目大意:找几个字串的最长公共子串。如小于3则输出no siginificant commonalities

 

思路:

用其他的字符串对每一个字串的后缀进行匹配,计录每个字串能匹配到的最大长度,然后所有串取min.

再把所有后缀的min取个max即可

 

#include
#include
#include
#include
#include
using namespace std;int a[21][71];int s[71],next[71];int m,ap,ple,xzq,n,i,j,k,x,z,q,t,l,T;char c;bool p;void Read(){ m=0; while(c=getchar(),c<'A'||c>'Z'); a[i][++m]=c; while(c=getchar(),c>='A'&&c<='Z'){ a[i][++m]=c; if(m==60)break; }}bool compare(int x,int z,int q){ int i; for(i=1;i<=q;i++){ if(a[1][x+i-1]
a[1][z+i-1])return false; } return false;}int main(){ scanf("%d",&t); for(T=1;T<=t;T++){ memset(a,0,sizeof(a)); xzq=0; scanf("%d",&n); for(i=1;i<=n;i++){ Read(); } for(i=1;i<=58;i++){ for(j=i;j<=60;j++)s[j-i+1]=a[1][j]; l=60-i+1; memset(next,0,sizeof(next)); x=0; for(j=2;j<=l;j++){ while(x!=0&&s[j]!=s[x+1])x=next[x]; if(s[j]==s[x+1])x++; next[j]=x; } ple=0; for(j=2;j<=n;j++){ ap=0; x=0; for(k=1;k<=60;k++){ while(x!=0&&a[j][k]!=s[x+1])x=next[x]; if(a[j][k]==s[x+1])x++; if(x>ap)ap=x; if(x==l)x=next[x]; } if(ple==0||ap
xzq){ xzq=ple; z=i; q=ple; } else if(ple==xzq){ p=compare(z,i,ple); if(p==false){ z=i; q=ple; } } } if(xzq<3)printf("no significant commonalities\n"); else{ for(i=z;i

 

转载于:https://www.cnblogs.com/applejxt/p/3801565.html

你可能感兴趣的文章
【原创+亲测可用】JS如何区分微信浏览器、QQ浏览器和QQ内置浏览器
查看>>
磁盘阵列卡
查看>>
UDP打洞
查看>>
Realtime Search: Solr vs Elasticsearch
查看>>
Java开发Maven环境配置和介绍
查看>>
CentOS7 防火墙
查看>>
htmlparser实现从网页上抓取数据(收集)
查看>>
[原创]FineUI秘密花园(二十三) — 树控件概述
查看>>
motion的移植和使用
查看>>
JavaEE PayPal退款流程
查看>>
SpringBoot之logback配置文件
查看>>
css居中,vue
查看>>
Swift 网络库封装整理 MVC + MVVM 两种设计
查看>>
[译]ES6入门(第二部分)
查看>>
移动跨平台开发深度解析
查看>>
(是时候开发属于自己的插件了)数据校验插件开发指南
查看>>
swift 文件修饰符
查看>>
VIPER 和 MVVM 到底有什么区别
查看>>
python
查看>>
启动页
查看>>