zoukankan      html  css  js  c++  java
  • Blue Jeans(串)

    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 10083   Accepted: 4262

    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

    题意:寻找m个序列中共有的最长的子串,长度小于3的输出no significant commonalities,长度相等时输出字典序小的;

    解题思路:枚举第一个序列的所有子串,每枚举出一个检查该子串是否是m个序列共有的,若是,比较该串与ans[]的长度取较长的,若长度相等取字典序小的;当枚举完所有子串后,ans[]保存的就是m个序列共有的最长的串。
     1 #include<stdio.h>
     2 #include<string.h>
     3 
     4 int main()
     5 {
     6     int i,j,k,n,t;
     7     char DNA[12][80],tmp[80],ans[80];
     8     scanf("%d",&t);
     9     while(t--)
    10     {
    11         ans[0] = '';
    12         scanf("%d",&n);
    13         for(i = 0; i < n; i++)
    14             scanf("%s",DNA[i]);
    15         for(i = 0; i < 60; i++)//枚举子串的起点
    16         {
    17             for(j = i+2; j < 60; j++)//枚举子串的终点
    18             {
    19                 int cnt = 0;
    20                 for(k = i; k <= j; k++)
    21                 {
    22                     tmp[cnt++] = DNA[0][k];
    23                 }
    24                 tmp[cnt] = '';//得到一个子串
    25                 for(k = 1; k < n; k++)
    26                 {
    27                     if(strstr(DNA[k],tmp) == NULL)
    28                         break;
    29                 }
    30                 if(k < n) continue;
    31                 if(strlen(ans) == strlen(tmp))
    32                 {
    33                     if(strcmp(ans,tmp) > 0)
    34                         strcpy(ans,tmp);
    35                 }
    36                 else
    37                 {
    38                     if(strlen(tmp) > strlen(ans))
    39                         strcpy(ans,tmp);
    40                 }
    41             }
    42         }
    43         if(strlen(ans) < 3) printf("no significant commonalities
    ");
    44         else printf("%s
    ",ans);
    45     }
    46     return 0;
    47 }
    View Code
    
    
    
     
  • 相关阅读:
    【转载】如何写一封有说服力的投稿信
    【实践】IEEE下载Citations并导入EndNote
    【实践】使用NotePad++编写批量添加文件名后缀的java程序
    【实践】如何下载Gurobi的历史版本
    【实践】origin画局部放大图,并和原图在一张图中(附演示视频)
    【实践】Origin设置图的跳点间隔
    【实践】多条曲线在一幅图上,Origin如何对每一条曲线单独设置
    Two classes of spectral conjugate gradient methods for unconstrained optimizations (Numerical testing reports)
    协同ADMM求解考虑碳排放约束直流潮流问题的对偶问题(附文章和程序下载地址)
    【实践】第十五届中国研究生数学建模竞赛之机场登机口调度第一问(附问题数据和程序)
  • 原文地址:https://www.cnblogs.com/LK1994/p/3256475.html
Copyright © 2011-2022 走看看