poj 3080 Blue Jeans

来源:互联网 发布:断电后mysql无法启动 编辑:程序博客网 时间:2024/06/03 15:54
Blue Jeans
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 16354 Accepted: 7260

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

Source

South Central USA 2006

提示

题意:

基因工程项目与IBM和美国国家地理杂志社会是研究伙伴关系,分析成千上万的DNA。

作为IBM的研究员,你的任务就是写一个程序,找到给定DNA片段的共同点使其可以与个人信息相关调查以确定新的遗传标记。有四个碱基:腺嘌呤(A)、胸腺嘧啶(T),鸟嘌呤(G)、胞嘧啶(C)。例如:6个碱基的DNA序列可以表示为TAGACC。

给定一组DNA碱基序列,确定在所有序列中的最长碱基序列。(最长公共子串)

最长子串不少于3个字符,有一样长的话输出字典序最小的,没有就输出no significant commonalities。

思路:

去暴力吧,还是0ms(⊙o⊙)哦。(附上测试样例)

示例程序

Source CodeProblem: 3080Code Length: 1828BMemory: 388KTime: 0MSLanguage: GCCResult: Accepted#include <stdio.h>#include <string.h>int n,m,i,i1,i2,i3,i4,l;char ch[10][61],a[61],b[61];//a[61]作为最长子串的中转点,因为如果一样长还需要比较字典序,b[61]才是最终答案int main(){    scanf("%d",&n);    for(i=1;n>=i;i++)    {        b[0]='#';//对是否有子串的字符数组初始化        scanf("%d",&m);        for(i1=0;m>i1;i1++)        {            scanf("%s",ch[i1]);        }        for(i1=60;i1>=3;i1--)//字串长度,从大到小        {            for(i2=0;60-i1>=i2;i2++)//同等长度不一样的子串            {                for(i3=1;m>i3;i3++)//开始比较,以第一个字符串为基准                {                    l=0;                    for(i4=0;60>i4;i4++)//寻找其他字符串是否存在这个字串                    {                        if(ch[0][i2+l]==ch[i3][i4])                        {                            l++;                        }                        else                        {                            l=0;                            if(ch[0][i2+l]==ch[i3][i4])                            {                                l++;                            }                        }                        if(l==i1)//有就跳出                        {                            break;                        }                    }                    if(i4==60)//没有说明这个字串不是                    {                        break;                    }                }                if(i4!=60)//i4没到60说明存在,并且有一样长的就比较                {                    for(l=0;i1>l;l++)                    {                        a[l]=ch[0][i2+l];                    }                    a[l]='\0';                    if(b[0]=='#'||strcmp(b,a)>0)                    {                        strcpy(b,a);                    }                }            }            if(b[0]!='#')//已找到答案            {                break;            }        }        if(b[0]!='#')        {            printf("%s",b);        }        else        {            printf("no significant commonalities");        }        printf("\n");    }    return 0;}

0 0
原创粉丝点击