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;
    }
    
  • 相关阅读:
    通过线程池,从hbase中拿数据
    phoenix如何压缩表,以及如何映射表
    spring boot改造现有jms activeMQ配置
    windows安装redis
    mysql免安装版配置
    转发和重定向的区别
    object.equals(null)和object==null区别
    用IDEA学习getRealPath遇到的问题
    总误按win+Enter键弹出讲述人
    戴尔电脑插耳机后声音变化问题
  • 原文地址:https://www.cnblogs.com/wejex/p/3247757.html
Copyright © 2011-2022 走看看