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 }
  • 相关阅读:
    096实战 在windows下新建maven项目
    095实战 ETL的数据来源,处理,保存
    094实战 关于js SDK的程序,java SDK的程序
    093实战 Nginx日志切割,以及脚本上传nginx的切割日志
    092实战 数据收集(各种事件)
    091实战 Nginx配置(日志服务器中关于日志的产生)
    android64位机子兼容32位.so库文件
    给 Android 初学者的 Gradle 知识普及
    Android重力感应开发
    随笔之Android平台上的进程调度探讨
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5677369.html
Copyright © 2011-2022 走看看