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. 整理的mysql优化内容

    1,当只要一行数据时使用 LIMIT 1如果明确只取一条数据,要加上limit 1; 2,避免 SELECT *,根据需要获取字段应该养成一个需要什么就取什么的好的习惯. 3,使用 ENUM 而不是 ...

  2. nginx禁止ip直接访问

    编辑一个noIp.conf放到虚拟目录中 server { listen default; server_name _; rewrite ^ http://www.xxxx.com/; } 其中 ww ...

  3. 大熊君大话NodeJS之------Net模块

    一,开篇分析 从今天开始,我们来深入具体的模块学习,这篇文章是这个系列(大熊君大话NodeJS)文章的第三篇,前两篇主要是以理论为主,相信大家在前两篇的学习中, 对NodeJS也有一个基本的认识,没事 ...

  4. Ubuntu 如何开启 SSH ?

    1.安装SS sudo apt-get install openssh-client # 用来登录别的机器的SSH sudo apt-get install openssh-server # 用来开放 ...

  5. BZOJ2466——[中山市选]树

    1.题目大意:给你一棵树,树的每个节点都有一个权值,是0或1,最开始都是0,你可以做一种修改操作,就是把一个节点和它相邻的 节点的权值取反,问最少几次修改能把所有节点的权值变得都是1,最多100个节点 ...

  6. BZOJ1901——Zju2112 Dynamic Rankings

    1.题目大意:区间第k小,有单点修改 2.分析:这个是树状数组套线段树,也是主席树....为什么主席树这么多QAQ 就是树套树的那种插入什么的,注意啊,一定要动态开内存..不然会爆.. 然后算答案有两 ...

  7. BZOJ1455——罗马游戏

    1.题目大意:维护一个数据结构,可以实现合并操作,还能询问最小值 2.分析:这种问题当然是可并堆啦 随便写了一个左偏树QAQ #include <cstdio> #include < ...

  8. 热更新脚本C#light,ulua,Scorpio性能比较

    http://www.unity蛮牛.com/thread-32861-1-1.html 测试环境: unity4.5.2  三个脚本全是源码导入  PC :处理器 Intel(R) Core(TM) ...

  9. c++ 操作符重载和友元

    操作符重载(operator overloading)是C++中的一种多态,C++允许用户自定义函数名称相同但参数列表不同的函数,这被称为函数重载或函数多态.操作符重载函数的格式一般为: operat ...

  10. 跟着百度学PHP[4]OOP面对对象编程-10-静态关键字static

    使用static关键字可以将类中的成员标识为静态的,既可以用来标识成员属性,也可以用来标识成员方法. 以Person类为例,如果在person类中有一个“$country=’china’”的成员属性, ...