Blue Jeans
2015-08-18 09:03
537 查看
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
Source
South Central USA 2006
题意:给你n个不超过60的字符串,问相同连续子串最长的是什么,如果子串长度小于3就输出no,昨天比赛没做~
心中万只草泥马奔腾
借鉴一下机房某小哥的代码
骚年进步空间很大
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 14324 | Accepted: 6380 |
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
题意:给你n个不超过60的字符串,问相同连续子串最长的是什么,如果子串长度小于3就输出no,昨天比赛没做~
心中万只草泥马奔腾
借鉴一下机房某小哥的代码
#include<iostream> #include<cstdio> #include<cstring> using namespace std; #define N 66 char str , s ; int n, len; int judge(char q[]) { for(int i = 1; i < n; i++) { if(strstr(str[i], q) == NULL) // 在其他字符串中未找到返回0 return 0; } return 1; } void slove() { char s1 ; int l = strlen(str[0]); for(int i = l; i >= 0; i--) { for(int j = 0; j+i<= l; j++) // 暴力枚举每一个子串,60小case { memset(s1, 0, sizeof(s1)); strncpy(s1, str[0]+j, i); if(judge(s1)) { if(len) //如果有了存在的长度,要判断字符串的字典序 { int l1 = strlen(s); int l2 = strlen(s1); if(l1 == l2) // 长度相同的时候取字典序较小的那个。 if(strcmp(s, s1)) { strcpy(s, s1); len = i; } } else //如果还没有存在的len直接复制就行 { strcpy(s, s1); len = i; } } } } } int main() { int t; scanf("%d", &t); while(t--) { len = 0; scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%s", str[i]); slove(); if(len < 3) printf("no significant commonalities\n"); // 长度小于3,就输出no else puts(s); // 长度大于3,输出相同公共子串 } return 0; }
骚年进步空间很大
相关文章推荐
- Reveal UI 分析工具简单使用
- UITabBar(第二次启动程序默认界面是上一次退出时的界面)
- UICollectionView的使用介绍
- UICollectionView的使用介绍
- nyoj 1100 WAJUEJI which home strong!
- UI导航控制器-----连载七
- Implementing Queue using Stacks
- Implementing Stacks Using Queues
- KVC中setValuesForKeysWithDictionary:
- UIImage尺寸调节
- UIActivityIndicatorView的详细使用
- Codeforces Round #316 (Div. 2) D. Tree Requests 树 离线在线 算法
- Round #313 (Div. 2) D. Equivalent Strings-大水题递归
- SPOJ-QTREE2 Query on a tree II(暴力+LCA)
- 为什么GUI框架都使用单线程
- OC学习笔记21--OC中集合类的读写文件操作及NSData与NSValue
- suid验证
- 纯UILabel实现文字的竖排显示 记录
- Codeforces Gym 100431G Persistent Queue 可持久化队列
- 自己用反射写的一个request.getParameter工具类