POJ 3080-Blue Jeans【kmp,字符串剪接】
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 20695 | Accepted: 9167 |
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
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<iostream>
#define nb main
#define i6g3y int
using namespace std; const int maxn = 100+10;
const int INF = 0x3f3f3f3f; using namespace std; string s[100]; int mynext[maxn];
void getnext(string a,int len){
int i,j;
j=mynext[0]=-1;
i=0;
while(i<len){
while(-1!=j&&a[i]!=a[j])j=mynext[j];
mynext[++i]=++j;
}
}
bool kmpcount(string a,int len1,string b,int len2){
int i,j;
i=j=0;
while(i<len2){
while(-1!=j&&a[j]!=b[i])j=mynext[j];
i++;j++;
if(j>=len1){
return true;
}
}
return false;
}
bool mycmp(string a,string b){
if(a.length()>b.length())return true;
else return b.compare(a);
}
i6g3y nb()
{
int t;
std::ios::sync_with_stdio(false);
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=0;i<n;i++)cin>>s[i];
string best="";
bool flag=false;//标志这个长度的这个串有没有匹配
bool Allflag=false;//标志这个长度有没有匹配
int i;
for(i=1;i<=60;i++){//长度
Allflag=false; //假设这个长度不可以
for(int first=0;first<60-i+1;first++){//起点
flag=true;//假设这个串可以
string test=s[0].substr(first,i);//模式串 getnext(test,i);//求next
for(int g=1;g<n;g++){
if(!kmpcount(test,i,s[g],60)){//如果有一个不匹配
flag=false;
break;
}
}
if(flag){//如果匹配
//cout<<"test "<<test;
//cout<<" 可以匹配"<<endl;
Allflag=true;
if(mycmp(test,best)){
best=test;
}
}
}
if(!Allflag){
break;
}
}
if(i<3)cout<<"no significant commonalities"<<endl;
else cout<<best<<endl;
}
return 0;
}
POJ 3080-Blue Jeans【kmp,字符串剪接】的更多相关文章
- poj 3080 Blue Jeans【字符串处理+ 亮点是:字符串函数的使用】
题目:http://poj.org/problem?id=3080 Sample Input 3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCA ...
- 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: ...
- poj 3080 Blue Jeans 解题报告
题目链接:http://poj.org/problem?id=3080 该题属于字符串处理中的串模式匹配问题.题目要求我们:给出一个DNA碱基序列,输出最长的相同的碱基子序列.(保证在所有的序列中都有 ...
- 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 ...
- POJ 3080 Blue Jeans、POJ 3461 Oulipo——KMP应用
题目:POJ3080 http://poj.org/problem?id=3080 题意:对于输入的文本串,输出最长的公共子串,如果长度相同,输出字典序最小的. 这题数据量很小,用暴力也是16ms,用 ...
- poj 3080 Blue Jeans (暴力枚举子串+kmp)
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- POJ - 3080 Blue Jeans 【KMP+暴力】(最大公共字串)
<题目链接> 题目大意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 限制条件: 1. 最长公共串长度小于3输出 no significant co ...
随机推荐
- 《数据结构》C++代码 堆(优先队列)
堆,是优先队列最常用的一种实现方式.在优先队列中,每个元素都被赋予了一个优先级,而每次出队时都让优先级最高的元素出队.堆,则是一种存储优先队列的方法,特指以一棵树形式存储的优先队列.最常用的是二叉堆, ...
- 关于windows10设置环境变量的问题
在设置环境变量的时候往往在网上能找到这样的文章: 1:新建环境变量 2:将新增的环境变量 加到path 变量中: 3.由于有的小伙伴的 系统是 windows10 在点击 编辑path 环境变量的时候 ...
- uiautomator+cucumber实现移动app自动化测试
前提 由于公司业务要求,所以自动化测试要达到以下几点: 跨应用的测试 测试用例可读性强 测试报告可读性强 对失败的用例有截图保存并在报告中体现 基于以上几点,在对自动化测试框架选型的时候就选择了uia ...
- excel批量导入
https://www.cnblogs.com/mingyue1818/p/4828865.html
- yum常规操作的基本用法
比如说,我想用nano编辑器的,发现没有安装, 这个时候你就可以用$ yum search nano 查询nano属于哪个安装包下. 发现就有nano这个安装包, 这个时候安装一下这个安装包,$ su ...
- Entity Framework(三)---FluentAPI和增删查改
一.FluentAPI: 1.基本配置: namespace ConsoleApp14.ModelConfig { public class PersonConfig: EntityTypeConfi ...
- 【视觉SLAM14讲】ch3课后题答案
1.验证旋转矩阵是正交矩阵 感觉下面这篇博客写的不错 http://www.cnblogs.com/caster99/p/4703033.html 总结一下:旋转矩阵是一个完美的矩阵——正交矩阵.①行 ...
- js万年历
首先,注意: 1.延迟执行 window.setTimeout( , ) 里面的时间是以毫秒计算的 2.间隔执行 window.setInterval( , ...
- java 用Arrays.binarySearch解读 快速定位数字范围
在一些时候,需要用给一个数字找到适合的区间,Arrays.binarySearch可达到这个目的. static int binarySearch(int[] a, int key) ...
- ocrosoft Contest1316 - 信奥编程之路~~~~~第三关 问题 C: 挂盐水
http://acm.ocrosoft.com/problem.php?cid=1316&pid=2 题目描述 挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下:然后滴二滴,停一下:再滴三滴 ...