zoukankan      html  css  js  c++  java
  • ACM Data Structure Blue Jeans

     

    A - Blue Jeans

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    Submit Status

    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
    
    暴力搜索
     
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #define LEN 60
    using namespace std;
    
    int main()
    {
        int i,j;
        int test;
        scanf("%d",&test);
        for(int t = 1; t<=test;t++)
        {
            int n;
            scanf("%d",&n);
            char DNA[10][LEN+1];
            for(int p=0;p<n;p++)
            {
                scanf("%s",&DNA[p]);
            }
    //        for(int p=0;p<n;p++)
    //        {
    //            printf("%s
    ",DNA[p]);
    //        }
    
            char obj[LEN +1];
            int Strlen =0 ;
            int length = 1;
    
            for(int i=0;;i++)
            {
                char dna[LEN+1];
                int pi = i;
                if(pi+length >LEN)
                {
                    length ++;
                    i = -1;
                    if(length >LEN)
                        break;
                    continue;
                }
                for(j=0;j<length;j++)
                    dna[j]= DNA[0][pi++];
                dna[j] = '';
    
                bool flag = true;
                for(int k = 1;k<n;k++)
                {
                    if(!strstr(DNA[k],dna))
                    {
                        flag =false;
                        break;
                    }
                }
    
                if(flag)
                {
                    if(Strlen<length)
                    {
                        Strlen = length;
                        strcpy(obj,dna);
    
                    }
                    else if(Strlen == length)
                    {
                        if(strcmp(obj,dna) > 0)
                        {
                            strcpy(obj,dna);
                        }
                    }
                }
            }
    
            if(Strlen <3)
                puts("no significant commonalities");
            else
                printf("%s
    ",obj);
    
    
        }
        return 0;
    }
    
  • 相关阅读:
    Python3.x和Python2.x的区别
    urllib库python2和python3具体区别
    Oracle实现自增方式:序列+触发器
    菜单
    visual studio 2013连接Oracle 11g并获取数据:(二:实现)
    Oracle连接出现TNS:no listener或者ORA-12514: TNS:listener does not currently know
    visual studio 2013连接Oracle 11g并获取数据:(一:环境搭建)
    C#编程
    Oracle 11g 安装
    Android在Eclipse上的环境配置
  • 原文地址:https://www.cnblogs.com/wejex/p/3247757.html
Copyright © 2011-2022 走看看