poj 3080 Blue Jeans (暴力枚举子串+kmp)
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
题意:给你m组DNA 要求你找到 最长公共的子串
思路:以第一个字符串为准 枚举 起点为 j 长度为 i 的子串 然后对其他字符串进行匹配(这个算法也是比较慢了)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define ll long long int
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
string s[];
int dp[];
void getnext(string t){
dp[]=;
for(int i=,j=;i<=t.length();i++){
while(j>&&t[i-]!=t[j]) j=dp[j];
if(t[i-]==t[j]) j++;
dp[i]=j;
}
}
bool kmp(string t,string p){
int len1=p.length();
int len2=t.length();
for(int i=,j=;i<=len1;i++){
while(j>&&p[i-]!=t[j]) j=dp[j];
if(p[i-]==t[j]) j++;
//cout<<j<<endl;
if(j==len2)
return true;
}
return false;
}
int main(){
ios::sync_with_stdio(false);
int n;
cin>>n;
while(n--){
int m;
cin>>m;
for(int i=;i<m;i++)
cin>>s[i];
int len=s[].length();
string ans="";
for(int i=;i<=len;i++){
for(int j=;j<=len-i;j++){
string temp=s[].substr(j,i);
getnext(temp);
bool jug=;
for(int k=;k<m;k++)
jug&=kmp(temp,s[k]); //一假必假
if(jug){
if(ans.size()<temp.size()) ans=temp;
else if(ans.size()==temp.size()) ans=min(ans,temp);
}
}
//cout<<ans<<endl;
}
if(ans.size()<) cout<<"no significant commonalities"<<endl;
else cout<<ans<<endl;
}
return ;
}
poj 3080 Blue Jeans (暴力枚举子串+kmp)的更多相关文章
- 字符串截取模板 && POJ 3450、3080 ( 暴力枚举子串 && KMP匹配 )
//截取字符串 ch 的 st~en 这一段子串返回子串的首地址 //注意用完需要根据需要最后free()掉 char* substring(char* ch,int st,int en) { ; c ...
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20966 Accepted: 9279 Descr ...
- POJ 3080 Blue Jeans (字符串处理暴力枚举)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21078 Accepted: ...
- POJ3080 Blue Jeans —— 暴力枚举 + KMP / strstr()
题目链接:https://vjudge.net/problem/POJ-3080 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total ...
- POJ 3080 Blue Jeans(Java暴力)
Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...
- poj 3080 Blue Jeans
点击打开链接 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10243 Accepted: 434 ...
- hdu_2328_Corporate Identity(暴力枚举子串+KMP)
题目链接:hdu_2328_Corporate Identity 题意: 给你n个串,让你找这n个串的最大公共子串 题解: 串比较小,暴力枚举第一个的子串,然后KMP判断是否可行 #include&l ...
- poj 3080 Blue Jeans【字符串处理+ 亮点是:字符串函数的使用】
题目:http://poj.org/problem?id=3080 Sample Input 3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCA ...
随机推荐
- PHP优化与提升
一.十个不错的建议 1.使用 ip2long() 和 long2ip() 函数来把 IP 地址转化成整型存储到数据库里.这种方法把存储空间降到了接近四分之一(char(15) 的 15 个字节对整形的 ...
- STL中vector、set、list和map
- CMake--静态库与动态库构建
小结内容 建立一个静态库和动态库,提供 HelloFunc 函数供其他程序编程使用, HelloFunc 向终端输出Hello World 字符串. 安装头文件与共享库. 1.代码与CMakeList ...
- spring MVC请求处理类注解属性详解
- oninput和onchange的区别
菜鸟教程: oninput事件:HTML5标准事件 当用户向<input>中尝试输入时执行JavaScript: <input type="text" oninp ...
- Dart语法基础
hello world // Define a function. printNumber(num aNumber) { print('The number is $aNumber.'); // Pr ...
- Linux 的相关操作
切换权限 在linux环境下,用户之前的切换使用 “su - name,若要切换到root下面,则使用sudo su 命令即可. 在linux下安装软件,经常就是装完后不知道装到哪里去了 (201 ...
- java使用顺序存储实现队列
详细连接 https://blog.csdn.net/ljxbbss/article/details/78135993 操作系统:当电脑卡的时候,如果不停点击,还是卡死,最后终于电脑又好了以后,操作 ...
- Fetch API & Delete & HTTP Methods
Fetch API & Delete & HTTP Methods vue https://developer.mozilla.org/en-US/docs/Web/API/Fetch ...
- python设计模式第二十五天【访问者模式】
1.应用场景 (1)将数据和行为进行分离,不同的角色具有不同的行为 2.代码实现