Match:Blue Jeans(POJ 3080)
题目大意:给你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)的更多相关文章
- (字符串 KMP)Blue Jeans -- POJ -- 3080:
链接: http://poj.org/problem?id=3080 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#probl ...
- Blue Jeans - POJ 3080(多串的共同子串)
题目大意:有M个串,每个串的长度都是60,查找这M个串的最长公共子串(连续的),长度不能小于3,如果同等长度的有多个输出字典序最小的那个. 分析:因为串不多,而且比较短,所致直接暴力枚举的第一个串 ...
- Blue Jeans - poj 3080(后缀数组)
大致题意: 给出n个长度为60的DNA基因(A腺嘌呤 G鸟嘌呤 T胸腺嘧啶 C胞嘧啶)序列,求出他们的最长公共子序列 使用后缀数组解决 #include<stdio.h> #include ...
- Blue Jeans POJ 3080 寻找多个串的最长相同子串
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- poj 3080 Blue Jeans
点击打开链接 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10243 Accepted: 434 ...
- POJ 3080 Blue Jeans (字符串处理暴力枚举)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21078 Accepted: ...
- POJ 3080 Blue Jeans(Java暴力)
Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...
- POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20966 Accepted: 9279 Descr ...
随机推荐
- CF448C Painting Fence (分治递归)
Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...
- [设计模式] javascript 之 责任链模式
责任链模式:定义 责任链接模式又称职责链模式,是一种对象的行为模式:它是一种链式结构,每个节点都有可能两种操作,要么处理该请求停止该请求操作,要么把请求转发到下一个节点,让下一个节点来处理请求:该模式 ...
- 【CISP笔记】安全漏洞与恶意代码(1)
恶意代码 类型二进制代码.脚本语言.宏语言等表现形式病毒.蠕虫.后门程序.木马.流氓软件.逻辑炸弹等 恶意代码的传播方式(1)移动存储 自动播放功能.Windows默认.自动执行autorun.inf ...
- 修改dedecms默认文章来源 "未知"改为关键词
在dedecms后台发表文章时文章来源是可选的,有时我们没有选择或没填写,那么前台默认文章来源即“未知”.如何将dedecms默认文章来源改为自己想要的关键词呢?即将“未知”改为“keyword”呢? ...
- FineUI第十八天---表格之事件的处理
表格之事件的处理: 1.事件参数: GridPageEventArgs:表格分页事件参数,对应onPageIndexChange事件. NewPageIndex:新页面的索引 GridSortEven ...
- phpcms数据库操作
http://www.cnblogs.com/suihui/archive/2013/08/01/3229821.html 一.查 ①select($where = '', $data = '*', ...
- UOJ52——【UR #4】元旦激光炮
1.题目大意:就是给你三个数组啦,然后让你找到其中的第K大,但是,不可以直接访问数组,必须通过一种函数,最后的分数 是看调用几次这个函数,100次以内10分,2000以内6分.... 2.分析:最开始 ...
- [KOJ6997]旅行商问题二
[COJ6997]旅行商问题二 试题描述 Bob是一名旅行商,Bob同时也是一个哲学家,他深知到了一个地方就要掏出钱包把所有景点都玩到.一个城市有N个景点,其中N-1条无向道路链接成一个连通图.Bob ...
- 关于tableView的错误提示
WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWit ...
- PHP运算符:算数运算符、逻辑运算符、三目运算符、位运算符、字符串运算符。
赋值运算符 PHP 赋值运算符用于向变量写值. PHP 中基础的赋值运算符是 "=". 这意味着右侧复制表达式会为左侧运算数设置值. _______________________ ...