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. codevs2574 波兰表达式

    题目描述 Description 对于 加.减.乘.除这种四则运算的表达式,我们使用的是先乘除.后加减的从左到右的顺序进行运算,如果要指定特定的顺序,就要增加括号进行表达,比如 (A+B)*C , A ...

  2. 统计学 nested_design 嵌套设计

    nested_design 嵌套设计 li_volleyball ,邓邦良 2016年3月6日 嵌套设计 一.基本概念 嵌套设计(nested design)又称为窝设计和套设计,与析因设计的处理不同 ...

  3. 15个关于Chrome的开发必备小技巧

    一.快速查找文件 如果你使用过Sublime,那么你会知道’Go to anything’的强大.没错,Chrome现在也有了这一功能. 操作如下: 1.F12打开你的Chrome调试器: 2.按下C ...

  4. HDOJ 4734 F(x)

    数位DP.... F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  5. Thank you for your resubmission. Performance - 2.3.10 We noticed that your app or its metadata includes irrelevant third-party platform information. Specifically, Android logo is mentioned in the

    被拒很多次,各种修改,最后发现是提交的时候,含有安卓的图标!欲哭无泪呀! Thank you for your resubmission. Performance - 2.3.10 We notice ...

  6. 北京程序员 VS 硅谷程序员(转)

    夫妻双码农,北京 or 硅谷,值得吗? http://mp.weixin.qq.com/s?__biz=MzA5MzE4MjgyMw==&mid=401228574&idx=1& ...

  7. Mac安装OpenCV

    安装过程参考这篇文章Mac平台上OpenCV开发环境搭建 也可以参考文档官网上的安装文档Installation in Linux(不知道为什么没有Installation in Mac...) 我的 ...

  8. Ubuntu 下apache2开启rewrite隐藏index.php

    为了实现 http://www.example.com/route/route 而不是 http://www.example.com/index.php/route/route 需要开启apache2 ...

  9. 15天学会jquery

    第二章 15 Days of jQuery 比window.onload 更快一些的载入 window.onload()是传统javascript 里一个能吃苦耐劳的家伙.它长久以来一直 被程序员们作 ...

  10. Sqli-LABS通关笔录-16

    这个关卡之前我还使用了一下工具跑,发现居然跑不出来.这就尴尬了.行吧手工试试. payload admin") and If(ascii(substr(database(),1,1))=11 ...