POJ-3080 Blue Jeans(纯暴力)
2016-07-27 20:09
513 查看
C - Blue Jeans
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld
& %llu
Submit Status Practice POJ
3080
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
这道题但是真的想了太久,一直纳闷kmp怎么跑n个字符,
后来查了题解才知道原来无脑暴力就能过,真是醉了。
大致题意和思路:
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld
& %llu
Submit Status Practice POJ
3080
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
这道题但是真的想了太久,一直纳闷kmp怎么跑n个字符,
后来查了题解才知道原来无脑暴力就能过,真是醉了。
大致题意和思路:
找出n个串中最长的公共串,并且要求字典序最大
直接枚举第一串的所有子串,然后与后面的所有串进行比较即可
拓展:<p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: rgb(69, 69, 69); font-family: arial, 宋体, sans-serif, tahoma, 'Microsoft YaHei'; font-size: 14px; line-height: 24px;">strstr(str1,str2);</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: rgb(69, 69, 69); font-family: arial, 宋体, sans-serif, tahoma, 'Microsoft YaHei'; font-size: 14px; line-height: 24px;"> 函数用于判断字符串str2是否是str1的子串。如果是,则该函数返回str2在str1中首次出现的地址;否则,返回NULL。</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: rgb(69, 69, 69); font-family: arial, 宋体, sans-serif, tahoma, 'Microsoft YaHei'; font-size: 14px; line-height: 24px;"><pre name="code" class="cpp">#include<stdio.h> #include<string.h> #include<stdlib.h> #include<limits.h> #include<algorithm> using namespace std; int n,m; char a[15][65]; char b[65],c[65]; int main() { int T,i,j; scanf("%d",&T); while(T--) { memset(c,'\0',sizeof(c)); scanf("%d",&n); for(i=1;i<=n;i++) scanf("%s",a[i]); for(i=1;i<=60;i++) { int flag=0; for(j=0;j<=60-i;j++) { int len=0; int check=1; for(int k=j;;k++) { b[len++]=a[1][k]; if(len==i) break; } b[len]='\0'; for(int k=2;k<=n;k++) { if(!strstr(a[k],b)) { check=0; break; } } if(check) { flag=1; if(strlen(c)<strlen(b)) strcpy(c,b); if(strcmp(c,b)>0) strcpy(c,b); } } if(!flag) break; } if(strlen(c)<3) printf("no significant commonalities\n"); else printf("%s\n",c); } }
相关文章推荐
- 【Mysql】存储emoji表情报错(Incorrect string value: '\xF0\x9F\x98\x82\xF0\x9F...')的解决方案
- Unique Paths II
- Unique Paths
- 河南多校暑期训练-恢复赛 <字典树,最短路,queue,map,模拟,思维>
- 【priority_queue<int,vector<int>,greater<int>>优先队列 按照由小到大顺序】
- Question( category_id 关联 category_name)
- iOS -最全UIButton详解
- October query(数据库查询语句)
- Xilium.CefGlue怎么使用Js调用C#方法
- button上多一块蓝色
- UISearchBar的placeholder文字上移问题
- UIsearchBar的placeholder字体颜色和大小
- IPhone 自定义 UITableViewCell 行缩进
- reason: 'couldn't find a common superview for <UIView: 0x7ffc2e303270; frame = (0 0; 0 0); layer = <
- Arduino 权威指南 第二版 第二章 2.3 使用浮点数
- 代码手写UI,xib和StoryBoard间的博弈,以及Interface Builder的一些小技巧
- MJRefresh的上拉加载的隐藏
- 快速熟悉 PyQt5 与 Eric6 的极速 GUI 开发
- UITableView代理方法执行顺序测试
- 简单的UIScrollView循环滑动