poj3080 Blue Jeans【KMP】【暴力】
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions:21746 | Accepted: 9653 |
Description
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
- 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
Sample Input
3
2
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
3
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
3
CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
Sample Output
no significant commonalities
AGATAC
CATCATCAT
Source
题意:
给定$m$个场长度为$60$的字符串,问他们的最长公共子串。
思路:
因为$m$和长度都很小,所以可以暴力枚举一个串的所有子串,$KMP$进行匹配。
等之后【后缀数组】刷熟练一点了再用后缀数组做一次。奇怪的是hdu2328明明是一样的题意,怎么就总是WA
#include<iostream>
//#include<bits/stdc++.h>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<climits>
#include<map>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
#define pi 3.1415926535
#define inf 0x3f3f3f3f const int maxn = ;
int n, m;
char str[][maxn];
int nxt[maxn]; void getnxt(char *s)
{
int len = strlen(s);
nxt[] = -;
int k = -;
int j = ;
while(j < len){
if(k == - || s[j] == s[k]){
++k;++j;
if(s[j] != s[k]){
nxt[j] = k;
}
else{
nxt[j] = nxt[k];
}
}
else{
k = nxt[k];
}
}
} bool kmp(char *s, char *t)
{
getnxt(s);
int slen = strlen(s), tlen = strlen(t);
int i = , j = ;
while(i < slen && j < tlen){
if(j == - || s[i] == t[j]){
j++;
i++;
}
else{
j = nxt[j];
}
}
if(j == tlen){
return true;
}
else{
return false;
}
} int main()
{
scanf("%d", &n);
while(n--){
scanf("%d", &m);
for(int i = ; i < m; i++){
scanf("%s", str[i]);
} char ans[maxn];
int anslen = -;
for(int i = ; i < ; i++){
for(int j = i; j < ; j++){
char t[maxn];
memcpy(t, str[] + i, j - i + );
t[j - i + ] = '\0';
bool flag = true;
for(int k = ; k < m; k++){
if(!kmp(str[k], t)){
flag = false;
break;
}
}
if(flag){
if(j - i + > anslen){
anslen = j - i + ;
strcpy(ans, t);
}
else if(j - i + == anslen){
if(strcmp(ans, t) > ){
strcpy(ans, t);
}
}
}
else{
break;
}
}
} if(anslen < ){
printf("no significant commonalities\n");
}
else{
//cout<<ans<<endl;
printf("%s\n", ans);
} }
return ;
}
poj3080 Blue Jeans【KMP】【暴力】的更多相关文章
- POJ3080 - Blue Jeans(KMP+二分)
题目大意 求N个字符串的最长公共字串 题解 和POJ1226做法一样...注意是字典序最小的...WA了一次 代码: #include <iostream> #include <cs ...
- POJ3080 Blue Jeans —— 暴力枚举 + KMP / strstr()
题目链接:https://vjudge.net/problem/POJ-3080 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total ...
- POJ3080——Blue Jeans(暴力+字符串匹配)
Blue Jeans DescriptionThe Genographic Project is a research partnership between IBM and The National ...
- POJ 3080 Blue Jeans(Java暴力)
Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...
- kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans
The Genographic Project is a research partnership between IBM and The National Geographic Society th ...
- poj3080 Blue Jeans(暴枚+kmp)
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- POJ3080 Blue Jeans 题解 KMP算法
题目链接:http://poj.org/problem?id=3080 题目大意:给你N个长度为60的字符串(N<=10),求他们的最长公共子串(长度>=3). 题目分析:KMP字符串匹配 ...
- POJ-3080-Blue jeans(KMP, 暴力)
链接: https://vjudge.net/problem/POJ-3080#author=alexandleo 题意: 给你一些字符串,让你找出最长的公共子串. 思路: 暴力枚举第一个串的子串,挨 ...
- Blue Jeans---poj3080(kmp+暴力求子串)
题目链接:http://poj.org/problem?id=3080 题意就是求n个长度为60的串中求最长公共子序列(长度>=3):如果有多个输出字典序最小的: 我们可以暴力求出第一个串的所有 ...
随机推荐
- MySql之删除操作
一:删除特定行 DELETE FROM 表名 WHERE 条件: 二:删除所有行 TRUNCATE TABLE 表名; //删除重建一张表
- Vue加载组件、动态加载组件的几种方式
https://cn.vuejs.org/v2/guide/components.html https://cn.vuejs.org/v2/guide/components-dynamic-async ...
- 修改PHP上传文件大小设置
问题: 上传MV到服务器发现有最大文件限制: 50M 怎么修改呢? 度娘了一把, 修改php.ini文件的upload_max_filesize = 100M 及 post_max_size = 10 ...
- [转]Linux性能分析工具汇总合集
出于对Linux操作系统的兴趣,以及对底层知识的强烈欲望,因此整理了这篇文章.本文也可以作为检验基础知识的指标,另外文章涵盖了一个系统的方方面面.如果没有完善的计算机系统知识,网络知识和操作系统知识, ...
- 从Zero到Hero,OpenAI重磅发布深度强化学习资源
https://zhuanlan.zhihu.com/p/49044306 https://spinningup.openai.com/en/latest/
- python os.system()和os.popen()
1>python调用Shell脚本,有两种方法:os.system()和os.popen(),前者返回值是脚本的退出状态码,后者的返回值是脚本执行过程中的输出内容.>>>hel ...
- 【系统移植】uboot详细分析
uboot使用 uboot控制台,倒计时 命令: 调试,操作一些硬件 setenv printenv saveenv nand erase nand write tftp zImage h ...
- 【Python】将python3.6软件的py文件打包成exe程序
下载pyinstaller pyinstaller 改变图标 pyinstaller -F --icon=my.ico xxx.py 采用命令行操作的办法 在cmd命令行中,输入代码: 首先,前往Py ...
- ArcGIS Runtime SDK for iOS开发地图图层-图形图层
注:本文翻译自:https://developers.arcgis.com/ios/objective-c/guide/creating-a-graphics-layer.htm 创建图 ...
- 带cookie跨域问题的思路以及echo的解决方案
问题起因 前后端分离,前端要访问后端资源,而且需要携带cookie信息,这时碰到了跨域问题.一开始以为设置为允许跨域allow_origins为即可.可是浏览器还是拦截的请求,于是查看跨域规则,原来跨 ...