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 }
  • 相关阅读:
    BurnInTest 设置屏蔽错误显示
    linux内核之模块参数及导出符号
    小程序设置背景图片
    微信小程序wxss样式文件中引用iconfont素材
    mac或linux中打开.bashrc,编辑完之后如何保存退出
    git clone 远程分支内容
    vue 自定义指令
    Vue笔记
    uniapp 小程序上获取不同机型 距离
    git 添加.gitignore文件不生效
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5677369.html
Copyright © 2011-2022 走看看