poj 3080 Blue Jeans
2015-10-01 10:21
363 查看
http://poj.org/problem?id=3080
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
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
3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA 3 CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
Sample Output
no significant commonalities AGATAC CATCATCAT
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <cstdlib> #include <limits> #include <queue> #include <stack> #include <vector> #include <map> using namespace std; #define N 4010 #define INF 0x3f3f3f3f #define PI acos (-1.0) #define EPS 1e-8 #define met(a, b) memset (a, b, sizeof (a)) struct node { char s ; int len; } p ; bool cmp (node a, node b) { return a.len < b.len; } char ss ; int main () { int t, n; scanf ("%d", &t); while (t--) { scanf ("%d", &n); for (int i=0; i<n; i++) { scanf ("%s", p[i].s); p[i].len = strlen (p[i].s); } sort (p, p+n, cmp); int flag, flag1 = 0; for (int i=p[0].len; i>1; i--) { for (int j=p[0].len-i; j>=0; j--) { met (ss, 0); strncpy (ss, p[0].s+j, i); flag = 0; for (int k=1; k<n; k++) if (!strstr (p[k].s, ss)) { flag = 1; break; } if (!flag) { puts (ss); flag1 = 1; break; } } if (flag1) break; } if (flag) puts ("no significant commonalities"); } return 0; }
相关文章推荐
- Demystifying ASM REQUIRED_MIRROR_FREE_MB and USABLE_FILE_MB
- [PAT]1101. Quick Sort (25)
- SEERC 2006 Subsequence, 高效算法设计 ,LA 2678
- iOS开发之窥探UICollectionViewController(三) --使用UICollectionView自定义瀑布流
- 尝试使用Grove Starter Kit for Arduino的LCD模块(彩色背光)
- hdu 5493 Queue 贪心+线段树
- SpriteBuilder中的碰撞分类(Categories)和掩码(Masks)
- SpriteBuilder中的碰撞分类(Categories)和掩码(Masks)
- SpriteBuilder中的碰撞分类(Categories)和掩码(Masks)
- MassMutual Interview Questions
- android.util.AndroidRuntimeException: requestFeature() must be called before adding content解决办法
- PE_BuildTime.html
- UGUI学习笔记2——Rect Transform
- Light oj 1277 - Looking for a Subsequence(LIS)
- 深入解析StringBuffer和StringBuilder的区别
- Ubiquitous Religions
- iOS:分段控件UISegmentedControl的详细使用
- GUI视窗
- HDU 5493 Queue(2015 ACM/ICPC Asia Regional Hefei Online )
- 每周学一点 egret(4):EUI