DNA序列

  题目大意:给你m串字符串,要你找最长的相同的连续字串

  这题暴力kmp即可,注意要按字典序排序,同时,是len<3才输出no significant commonalities

  

 #include <iostream>
#include <functional>
#include <algorithm>
#include <string.h>
#define MAX 60 using namespace std; typedef char* _String;
typedef int Position;
static char str[][],ans[];
static int _next[]; bool KmpSearch(_String, _String, const int);
void Get_Next(_String, const int);
void Search(const int); int main(void)//暴力枚举第一行
{
int case_sum, m;
//freopen("in.txt", "r", stdin);
scanf("%d", &case_sum); while (case_sum--)
{
scanf("%d", &m);
getchar(); for (int i = ; i < m; i++)
scanf("%s", str[i]);
Search(m);
}
return EXIT_SUCCESS;
} void Search(const int m)
{
int len, ans_len = -, pos, if_match;
char tmp; for (len = ; len <= MAX; len++)
{
for (pos = ; pos + len <= MAX; pos++)
{
if_match = ;
Get_Next(&str[][pos], len);
for (int i = ; i < m; i++)
if_match += KmpSearch(str[i], &str[][pos], len);
if (if_match == m - && len >= ans_len)
{
if (len == ans_len)
{
tmp = str[][pos + len];
str[][pos + len] = '\0';
if (strcmp(&str[][pos], ans) < )
strcpy(ans, &str[][pos]);
str[][pos + len] = tmp;
}
else if (len > ans_len)
{
ans_len = len;
tmp = str[][pos + len];
str[][pos + len] = '\0';
strcpy(ans, &str[][pos]);
str[][pos + len] = tmp;
}
}
}
}
if (ans_len < )
printf("no significant commonalities\n");
else
printf("%s\n", ans);
} bool KmpSearch(_String str_m, _String text, const int t_len)
{
Position i = , j = ; while (i < MAX && j < t_len)
{
if (j == - || str_m[i] == text[j])
{
i++;
j++;
}
else j = _next[j];
}
if (j == t_len)
return true;
else
return false;
} void Get_Next(_String text, const int t_len)
{
Position i = , k = -;
_next[] = -; while (i < t_len)
{
if (k == - || text[i] == text[k])
{
i++;
k++;
_next[i] = text[i] != text[k] ? k : _next[k];
}
else k = _next[k];
}
}

  

Match:Blue Jeans(POJ 3080)的更多相关文章

  1. (字符串 KMP)Blue Jeans -- POJ -- 3080:

    链接: http://poj.org/problem?id=3080 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#probl ...

  2. Blue Jeans - POJ 3080(多串的共同子串)

    题目大意:有M个串,每个串的长度都是60,查找这M个串的最长公共子串(连续的),长度不能小于3,如果同等长度的有多个输出字典序最小的那个.   分析:因为串不多,而且比较短,所致直接暴力枚举的第一个串 ...

  3. Blue Jeans - poj 3080(后缀数组)

    大致题意: 给出n个长度为60的DNA基因(A腺嘌呤 G鸟嘌呤 T胸腺嘧啶 C胞嘧啶)序列,求出他们的最长公共子序列 使用后缀数组解决 #include<stdio.h> #include ...

  4. Blue Jeans POJ 3080 寻找多个串的最长相同子串

    Description The Genographic Project is a research partnership between IBM and The National Geographi ...

  5. POJ 3080 Blue Jeans (求最长公共字符串)

    POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...

  6. poj 3080 Blue Jeans

    点击打开链接 Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10243   Accepted: 434 ...

  7. POJ 3080 Blue Jeans (字符串处理暴力枚举)

    Blue Jeans  Time Limit: 1000MS        Memory Limit: 65536K Total Submissions: 21078        Accepted: ...

  8. POJ 3080 Blue Jeans(Java暴力)

    Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...

  9. POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)

    Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20966   Accepted: 9279 Descr ...

随机推荐

  1. vim 配置,我本机的配置[windows]

    set nocompatible source $VIMRUNTIME/vimrc_example.vim source $VIMRUNTIME/mswin.vim behave mswin set ...

  2. 如何让 height:100%; 起作用

    当你设置一个页面元素的高度(height)为100%时,期望这样元素能撑满整个浏览器窗口的高度,但大多数情况下,这样的做法没有任何效果.你知道为什么height:100%不起作用吗? 按常理,当我们用 ...

  3. 繁华模拟赛day8 科技树

    /* 贪心,很明显是越容易升级的越先升级 */ #include<iostream> #include<cstdio> #include<string> #incl ...

  4. R语言 奇怪的NA

    > 1+NA [1] NA > NA==1 [1] NA > c(NA,1:50) [1] NA 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  5. nyoj 14 会场安排问题(贪心专题)java

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...

  6. asp.net—缓存

    1.页面缓存 要实现页面输出缓存,只要将一条 OutputCache 指令添加到页面即可. <%@ OutputCache CacheProfile=" " NoStore= ...

  7. Hadoop 面试题之storm 3个

    Hadoop 面试题之八 355.metaq 消息队列 zookeeper 集群 storm集群(包括 zeromq,jzmq,和 storm 本身)就可以完成对商城推荐系统功能吗?还有其他的中间件? ...

  8. VS2013 Community配置OpenCV3.0.0

    配置环境:32位win7系统+VS2013 Community版本 1.首先从OpenCV官网上下载最新版本的OpenCV for Windows. 2.直接双击打开下载得到的opencv-3.0.0 ...

  9. Windows下几个常用的和进程有关的命令

    在windows下,进入cmd,有几个常用的和进程有关的命令: netstat -ano:查看所有进程 netstat -ano|findstr  “端口号”:查看端口号对应的进程PID taskli ...

  10. am335x 1G nand 启动Linux qt

    针对DRAM的升级,修改u-boot 的参数即可. include/configs/ok335x.h 修改PHYS_DRAM_1_SIZE 为0x40000000  这是1G的大小. 原来512M 为 ...