• 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;
    }
    
  • 相关阅读:
    TWebBrowser 与 MSHTML(3): window 对象的属性、方法、事件纵览
    使 SaveDialog 对话框的文件名选择变灰 回复 "delphan" 的问题
    [最新通知]今日17:0019:00将不能访问博客园
    编辑器改进(三)
    博客园.Text技术支持移至PSP技术支持中心
    [公告]关于投稿到Dearbook的“读书笔记”专栏
    [致歉]博客园服务器停运时间超出计划时间
    [博客园公告]给发表评论增加了验证码功能
    CS Beta 1发布了
    [通知]11月6日(星期六)可能不能访问博客园
  • 原文地址:https://www.cnblogs.com/wejex/p/3247757.html
Copyright © 2020-2023  润新知