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;
    }
    
  • 相关阅读:
    【题解】CodeChef
    【题解】AT1984 Wide Swap(拓扑排序)
    【题解】CF917D Stranger Trees(prufer序列+二项式反演)
    【题解】UVA
    【题解】P3980 [NOI2008]志愿者招募(费用流求线性规划)
    【题解】AT2064 Many Easy Problems(转换+NTT)
    【题解】AT1983 BBQ Hard (格路)
    【总结】不同卷积如何来搞
    【瞎讲】 Cayley-Hamilton 常系数齐次线性递推式第n项的快速计算 (m=1e5,n=1e18)
    计算几何小结计算几何小结
  • 原文地址:https://www.cnblogs.com/wejex/p/3247757.html
Copyright © 2011-2022 走看看