poj-3080
2016-04-26 19:42
190 查看
Blue Jeans
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
Sample Output
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 15694 | Accepted: 6978 |
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 解体思路: KMP+暴力,就这么简单. 代码如下: #include<stdio.h> #include<string.h> int n,len2; char test[12][65],pat[65]; int per[65]; void get_per(){ int i,j; memset(per,0,sizeof(per)); per[0]=-1; i=0;j=-1; while(i<len2){ if(j==-1||pat[i]==pat[j]){ i++;j++; per[i]=j; } else j=per[j]; } } int KMP(){ int i,j,k,m; int ma=100; get_per(); for(k=1;k<n;k++){ i=0;j=0;m=0; while(i<60&&j<len2){ if(j==-1||test[k][i]==pat[j]){ i++;j++; } else j=per[j]; if(j>m)m=j;//从首元素开始,最长匹配长度 } if(ma>m) ma=m;//与所有字符串匹配的最小长度 } return ma; } int main(){ int t,i,ans; char re[65]; scanf("%d",&t); while(t--){ ans=0; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%s",test[i]); } for(i=0;i<=57;i++){//字符串至少长度为3 strcpy(pat,test[0]+i);//遍历test的后缀数组 len2=60-i; int l=KMP(); if(l>ans){ ans=l; strncpy(re,pat,l); re[l]='\0'; } else if(l==ans){ char re1[65];; strncpy(re1,pat,l); re1[l]='\0'; if(strcmp(re,re1)>0) strcpy(re,re1); } } if(ans>=3) printf("%s\n",re); else printf("no significant commonalities\n"); } return 0; }
相关文章推荐
- hdu 5672
- 【Java】String类的方法介绍
- mysql中触发器的应用
- poj2955,开始学习区间dp了
- jQuery事件绑定on()、bind()与delegate() 方法详解
- C#中扩展方法
- 霍夫变换
- Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version 9 declared
- Android中Adapter的notifyDataSetInvalidated()和notifyDataSetChanged()的区别!
- jquery [datatable]排序时指定某列不可排序
- (61)从零开始学习Nodejs[3]——Node TCP服务器&telnet,多客户端消息传递改进
- 作业6团队作业
- Web前端----Javascript模块化
- Java线程之1.5版新特性多生产者多消费者(四)
- 个人工作总结08
- iOS LLDB调试精解
- [原创]自定义BaseAcitivity的实现,统一activity的UI风格样式
- HTML 中 URL 传值。
- JAVA BigDecimal 小数处理
- Scaledrawable