博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3080 Blue Jeans (求最长公共字符串)
阅读量:5267 次
发布时间:2019-06-14

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

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

 

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

 

题意:给定长度为60的m个字符串,找它的最长公共子串,如果长度相同,输出字典序小的,如果找到的公共子串小于3 ,就输出 一串不认识的字母,否则就输出找到的那一串同样不认识的字母。

注意到,这个题给的数据范围很小,m不大于10,长度不大于60,吐过暴力枚举的话,复杂度大概是60*60*10*(60+60),不会爆,所以果断枚举,

暴力找就行,枚举相同序列的长度以第一个DNA为模板向其他串中找。其中有个技巧性的地方就是strstr()函数的使用,strstr(a,b)函数为在a中找b,如果可以找到b那么会返回最初始找到b时的位置的地址,若找不到b则返回NULL。

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 7 using namespace std; 8 9 int main()10 {11 //freopen("sample.txt","r",stdin);12 int n;13 scanf("%d",&n);14 while(n--)15 {16 char str[10][65];17 char ans[65];18 ans[0]=0;19 int m;20 scanf("%d",&m);21 getchar();22 for(int i=0;i
strlen(ans))47 strcpy(ans,ttm);48 else if(strlen(ttm)==strlen(ans)&&strcmp(ttm,ans)<0)49 strcpy(ans,ttm);50 }51 }52 if(!af)53 break;54 }55 if(strlen(ans)<3)56 printf("no significant commonalities\n");57 else58 puts(ans);59 }60 return 0;61 }
View Code

 

转载于:https://www.cnblogs.com/jiamian/p/11191778.html

你可能感兴趣的文章
Luogu_4103 [HEOI2014]大工程
查看>>
程序员常用软件,你用了哪些
查看>>
1043: [HAOI2008]下落的圆盘 - BZOJ
查看>>
线程同步之读写锁
查看>>
codeforces 620D Professor GukiZ and Two Arrays
查看>>
pylint
查看>>
Oracle——SQL基础
查看>>
Java设计模式(2)——工厂方法模式
查看>>
互联网基础之DIV和CSS二
查看>>
项目置顶随笔
查看>>
Redis的安装与使用
查看>>
传微软Windows Phone 7将更新支持HTML 5
查看>>
P1970 花匠
查看>>
query和exec区别
查看>>
java语言与java技术
查看>>
南阳22
查看>>
分享一次在Windows Server2012 R2中安装SQL Server2008
查看>>
NOIP2016提高A组五校联考2总结
查看>>
OpenStack_Glance
查看>>
Spring PropertyPlaceholderConfigurer数据库配置
查看>>