poj(3080)
题目链接:http://poj.org/problem?id=3080
学习博客:https://www.cnblogs.com/acjiumeng/p/6818213.html
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 21342 | Accepted: 9467 |
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
首先你必须遍历第一个串每一个子串长度的(60*60),然后求每一个子串的next[]数组,最大为60,最后和剩下的串进行比较,最大10*60,所以这道题最大的时间复杂度是(60*60*60*10*60),差不多刚好卡在时限左右
看代码:
- #include<iostream>
- #include<string.h>
- #include<map>
- #include<cstdio>
- #include<cstring>
- #include<stdio.h>
- #include<cmath>
- #include<ctype.h>
- #include<math.h>
- #include<algorithm>
- #include<set>
- #include<queue>
- typedef long long ll;
- using namespace std;
- const ll mod=;
- const int maxn=+;
- const int maxk=5e3+;
- const int maxx=1e4+;
- const ll maxe=+;
- #define INF 0x3f3f3f3f3f3f
- #define Lson l,mid,rt<<1
- #define Rson mid+1,r,rt<<1|1
- string a[];
- int next[maxn];
- void cal_next(string s)
- {
- int len=s.length();
- int k=-;
- next[]=-;
- for(int i=;i<len;i++)
- {
- while(k>-&&s[k+]!=s[i])
- {
- k=next[k];
- }
- if(s[k+]==s[i]) k++;
- next[i]=k;
- }
- }
- bool kmp(string x,string y)
- {
- int k=-;
- for(int i=;i<x.length();i++)
- {
- while(k>-&&y[k+]!=x[i])
- {
- k=next[k];
- }
- if(x[i]==y[k+]) k++;
- if(k==y.length()-) return true;
- }
- return false;
- }
- int main()
- {
- int t,n,flag=;
- scanf("%d",&t);
- while(t--)
- {
- string ans="";
- cin>>n;
- for(int i=;i<n;i++)
- {
- cin>>a[i];
- }
- for(int i=;i<=a[].size();i++)//遍历每一个长度
- {
- for(int j=;j+i<=a[].size();j++)//取每一个子串
- {
- flag=;
- string op=a[].substr(j,i);
- cal_next(op);//求每个子串的next[]
- for(int k=;k<n;k++)
- {
- if(!kmp(a[k],op))//和每一个串进行比较,看是否有不符合的,有点话直接break
- {
- flag=;
- break;
- }
- }
- if(flag==)
- {
- if(op.size()>ans.size()) ans=op;
- else if(op.size()==ans.size()) ans=min(op,ans);
- }
- }
- }
- if(ans.size()<) cout<<"no significant commonalities"<<endl;
- else cout<<ans<<endl;
- }
- return ;
- }
poj(3080)的更多相关文章
- POJ - 3294~Relevant Phrases of Annihilation SPOJ - PHRASES~Substrings POJ - 1226~POJ - 3450 ~ POJ - 3080 (后缀数组求解多个串的公共字串问题)
多个字符串的相关问题 这类问题的一个常用做法是,先将所有的字符串连接起来, 然后求后缀数组 和 height 数组,再利用 height 数组进行求解. 这中间可能需要二分答案. POJ - 3294 ...
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- POJ 3080 后缀数组/KMP
题目链接:http://poj.org/problem?id=3080 题意:给定n个DNA串,求最长公共子串.如果最长公共子串的长度小于3时输出no significant commonalitie ...
- poj 3080 Blue Jeans 解题报告
题目链接:http://poj.org/problem?id=3080 该题属于字符串处理中的串模式匹配问题.题目要求我们:给出一个DNA碱基序列,输出最长的相同的碱基子序列.(保证在所有的序列中都有 ...
- poj 3080 Blue Jeans(水题 暴搜)
题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...
- POJ 3080 Blue Jeans(后缀数组+二分答案)
[题目链接] http://poj.org/problem?id=3080 [题目大意] 求k个串的最长公共子串,如果存在多个则输出字典序最小,如果长度小于3则判断查找失败. [题解] 将所有字符串通 ...
- POJ 3080 Blue Jeans 后缀数组, 高度数组 难度:1
题目 http://poj.org/problem?id=3080 题意 有m个(2<=m<=10)不包含空格的字符串,长度为60个字符,求所有字符串中都出现过的最长公共子序列,若该子序列 ...
- (字符串 KMP)Blue Jeans -- POJ -- 3080:
链接: http://poj.org/problem?id=3080 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#probl ...
- poj 3080 Blue Jeans【字符串处理+ 亮点是:字符串函数的使用】
题目:http://poj.org/problem?id=3080 Sample Input 3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCA ...
随机推荐
- BZOJ1707:[Usaco2007 Nov]tanning分配防晒霜
我对贪心的理解:https://www.cnblogs.com/AKMer/p/9776293.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem ...
- 不重启linuxVMWare虚拟机添加虚拟磁盘
Vsphere Client找到要添加磁盘的虚机,如图所示 点击虚机右键,在出现的下列列表中选择“编辑设置”如图 在打开的虚拟机属性中,在”硬件对话框点击“添加"按钮,如图 在添 ...
- SqlServer2005的备份和还原(不同服务器)
1 备份数据库NorthSJ 进入服务器,进入SqlServer2005,选择数据库NorthSJ进行备份
- Android中EditTex焦点设置和弹不弹出输入法的问题(转)
今天编程碰到了一个问题:有一款平板,打开一个有EditText的Activity会默认弹出输入法.为了解决这个问题就深入研究了下android中焦点Focus和弹出输入法的问题.在网上看了些例子都不够 ...
- 用python做的windows和linx文件夹同步。解决自动同步、加快传输大量小文件的速度、更丰富的文件上传过滤设置。
现在工具不好用,用的pycharm自动同步,但对于git拉下来的新文件不能自动上传到linux,只有自己编辑过或者手动ctrl + s的文件才会自动同步.导致为了不遗漏文件,经常需要全量上传,速度非常 ...
- 用C语言实现一个公用库函数void * memmove(void *dest,const void *src,size_t n)
用C语言实现一个公用库函数void * memmove(void *dest,const void *src,size_t n). 该函数的功能是拷贝src所指的内存内容前n个字节到dest所指的地址 ...
- tar压缩解压缩
Linux下的tar压缩解压缩命令详解tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以 ...
- mvn jetty:run 出现PermGen space outofmemeryerror
使用mvn jetty:run跑别人的项目时出现了PermGen space outofmemeryerror异常 http://stackoverflow.com/questions/1451648 ...
- Python短小精悍的Orator查询构造器
查询构造器 介绍 这个数据库查询构造器,提供便利的接口可以创建和执行查询操作,可以在大多数数据库中使用. 查询select操作 查询表中所有的数据. users = db.table('users') ...
- 开源库ActiveAndroid + gson使用
ActiceAndroid的简介 ActiveAndroid是一个活跃的记录风格的ORM(对象关系映射)库.ActiveAndroid可以让您保存和检索的SQLite数据库记录而没有写一个SQL语句. ...