zoukankan      html  css  js  c++  java
  • Blue Jeans

    Blue Jeans
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 14324   Accepted: 6380

    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

    题意:给你n个不超过60的字符串,问相同连续子串最长的是什么,如果子串长度小于3就输出no,昨天比赛没做~
    心中万只草泥马奔腾
    借鉴一下机房某小哥的代码
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 
     5 using namespace std;
     6 #define N 66
     7 char str[N][N], s[N];
     8 int n, len;
     9 
    10 int judge(char q[])
    11 {
    12     for(int i = 1; i < n; i++)
    13     {
    14         if(strstr(str[i], q) == NULL)  // 在其他字符串中未找到返回0
    15             return 0;
    16     }
    17     return 1;
    18 }
    19 
    20 void slove()
    21 {
    22     char s1[N];
    23     int l = strlen(str[0]);
    24 
    25     for(int i = l; i >= 0; i--)
    26     {
    27         for(int j = 0; j+i<= l; j++)  // 暴力枚举每一个子串,60小case
    28         {
    29             memset(s1, 0, sizeof(s1));
    30             strncpy(s1, str[0]+j, i);
    31             if(judge(s1))
    32             {
    33                 if(len)  //如果有了存在的长度,要判断字符串的字典序
    34                 {
    35                     int l1 = strlen(s);
    36                     int l2 = strlen(s1);
    37                     if(l1 == l2)   // 长度相同的时候取字典序较小的那个。
    38                         if(strcmp(s, s1))
    39                         {
    40                             strcpy(s, s1);
    41                             len = i;
    42                         }
    43                 }
    44                 else //如果还没有存在的len直接复制就行
    45                 {
    46                     strcpy(s, s1);
    47                     len = i;
    48                 }
    49             }
    50         }
    51     }
    52 }
    53 
    54 int main()
    55 {
    56     int t;
    57     scanf("%d", &t);
    58     while(t--)
    59     {
    60         len = 0;
    61         scanf("%d", &n);
    62         for(int i = 0; i < n; i++)
    63             scanf("%s", str[i]);
    64         slove();
    65         if(len < 3)
    66             printf("no significant commonalities
    ");  // 长度小于3,就输出no
    67         else
    68             puts(s);  // 长度大于3,输出相同公共子串
    69     }
    70     return 0;
    71 }

    骚年进步空间很大

    让未来到来 让过去过去
  • 相关阅读:
    iptables在不重新编译内核以及iptables的情况下 加载iptables模块--在proxmox5中没有测试成功
    ip rule以及ip route的使用--非常重要,需要持续研究!!
    debian版本的相关说明
    分析 linux服务器单网卡在可配置多网关 提供服务的可能性--重要!!!!!
    关于pn定期执行的相关问题分析
    man在线手册-推荐使用debian官方网站
    牛客网暑期ACM多校训练营(第三场) J Distance to Work 计算几何求圆与多边形相交面积模板
    杭电多校第二场 hdu 6315 Naive Operations 线段树变形
    牛客网暑期ACM多校训练营(第三场) A PACM Team 01背包 记录路径
    牛客网暑期ACM多校训练营(第三场) E Sort String 哈希处理字符串(模板)
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4738341.html
Copyright © 2011-2022 走看看