zoukankan      html  css  js  c++  java
  • POJ3080 Blue Jeans

    Blue Jeans
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 16142   Accepted: 7189

    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
    

    Source

    暴力枚举长度,然后依次检查每个串是否匹配

     1 /*by SilverN*/
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<cmath>
     7 using namespace std;
     8 const int len=60;
     9 char s[20][65];
    10 char cp[65];
    11 int n;
    12 int main(){
    13     int i,j,k,T;
    14     scanf("%d",&T);
    15     int len;
    16     while(T--){
    17         scanf("%d",&n);
    18         char ans[100];
    19         memset(ans,'',sizeof ans);
    20         for(i=1;i<=n;i++)scanf("%s",s[i]);
    21         for(i=1;i<=60;i++){
    22             int find=0;
    23             for(j=0;j<=60-i;j++){
    24                 len=0;
    25                 int check=1;
    26                 for(k=j; ;k++){
    27                     cp[len++]=s[1][k];
    28                     if(len==i)break;
    29                 }
    30                 cp[len]='';
    31                 for(k=2;k<=n;k++){
    32                     if(!strstr(s[k],cp)){
    33                         check=0;
    34                         break;
    35                     }
    36                 }
    37                 if(check){
    38                     find=1;
    39                     if(strlen(ans)<strlen(cp)) strcpy(ans,cp);
    40                     else if(strcmp(ans,cp)>0) strcpy(ans,cp);
    41                 }
    42             }
    43             if(!find)break;
    44         }
    45         if(strlen(ans)<3) printf("no significant commonalities
    ");  
    46         else printf("%s
    ",ans); 
    47     }
    48     return 0;
    49 }
  • 相关阅读:
    Mysql问题1862
    S3TC IAP15F2K61S2点亮一个发光二极管keil和stc-isp软件操作
    .NET练习计算平方根
    求一个整数以内的素数(函数实现)
    判断一个数是不是素数(函数实现)
    #号在进制输出值的作用,美化输出
    分类——决策树模型(附有决策树生成步骤)
    分类:贝叶斯分类之新闻组数据组学习(查看数据类型的方法)(环境:Pycharm)
    分类:K-近邻分类之鸢尾花数据集学习(包含数据预处理中的标准化)(环境:Pycharm)
    编写一个程序,求2~n间的素数,n由键盘输入,循环变量分别 从2到n、2到(int)sqrt(n),分别测出两个循环的所用时间。
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5677369.html
Copyright © 2011-2022 走看看