poj3080 Blue Jeans
2017-04-05 17:35
330 查看
地址:http://poj.org/problem?id=3080
题目:
Blue JeansTime Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 17720 | Accepted: 7856 |
Description
The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was populated.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
Input to this problem will begin with a line containing a single integer n indicating the number of datasets. Each dataset consists of the following components:- 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
For each dataset in the input, output the longest base subsequence common to all of the given base sequences. If the longest common subsequence is less than three bases in length, display the string "no significant commonalities" instead. If multiple subsequences of the same longest length exist, output only the subsequence that comes first in alphabetical order.Sample Input
3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA 3 CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
Sample Output
no significant commonalities AGATAC CATCATCAT
Source
South Central USA 2006思路:暴力枚举+kmp
#include <cstdio> #include <cstring> #include <iostream> using namespace std; #define MP make_pair #define PB push_back typedef long long LL; const double eps=1e-8; const int K=1e6+7; const int mod=1e9+7; int nt[K],ans[K]; char sa[20][100],sb[100]; void kmp_next(char *T,int *next) { next[0]=0; for(int i=1,j=0,len=strlen(T);i<len;i++) { while(j&&T[i]!=T[j]) j=next[j-1]; if(T[i]==T[j]) j++; next[i]=j; } } int kmp(char *S,char *T,int *next) { int ans=0; int ls=strlen(S),lt=strlen(T); for(int i=0,j=0;i<ls;i++) { while(j&&S[i]!=T[j]) j=next[j-1]; if(S[i]==T[j]) j++; if(j==lt) ans++; } return ans; } int cmp(char *sb,int si,int st,int len) { for(int i=0;i<len;i++) if(sb[si+i]<sb[st+i]) return -1; else if(sb[si+i]>sb[st+i]) return 1; return 0; } int main(void) { int t,n;cin>>t; while(t--) { cin>>n; for(int i=1;i<=n;i++) scanf("%s",sa[i]); int len,st,se; len=strlen(sa[1]); st=se=0; for(int i=0;i<len;i++) { sb[0]=sa[1][i],sb[1]=sa[1][i+1]; for(int j=i+2;j<len;j++) { sb[j-i]=sa[1][j],sb[j-i+1]='\0'; int ff=1; kmp_next(sb,nt); for(int k=2;k<=n&&ff;k++) if(!kmp(sa[k],sb,nt)) ff=0; if(ff&&j-i>se-st) st=i,se=j; else if(ff&&j-i==se-st&&cmp(sa[1],i,st,j-i+1)<0) st=i,se=j; } } if(se-st+1<3) printf("no significant commonalities\n"); else { for(int i=st;i<=se;i++) printf("%c",sa[1][i]); printf("\n"); } } return 0; }
相关文章推荐
- POJ3080Blue Jeans(暴力)
- POJ3080 Blue Jeans
- POJ3080 Blue Jeans
- Blue Jeans(poj3080简单字符串匹配)
- POJ3080 Blue Jeans
- POJ3080Blue Jeans
- poj3080 blue Jeans
- [POJ3080 Blue Jeans]
- POJ3080 Blue jeans(未完待续,KMP,寻找多个子串的公共串)
- [POJ3080] Blue Jeans
- POJ3080 Blue Jeans(暴力kmp)
- POJ3080Blue Jeans
- POJ3080:Blue Jeans
- POJ3080 Blue Jeans
- poj3080Blue Jeans
- POJ3080 Blue Jeans(KMP,求最长公共子串)
- POJ3080:Blue Jeans
- poj3080 Blue Jeans(后缀数组+二分答案)
- poj3080Blue Jeans(在m个串中找到这m个串的 最长连续公共子序列)
- poj3080(Blue Jeans)kmp求多个串公共子串