POJ 3080--Blue Jeans【KMP && 暴力枚举】
来源:互联网 发布:nicelabel 数据库错误 编辑:程序博客网 时间:2024/05/16 07:42
Blue Jeans
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 14316 Accepted: 6374
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.
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
32GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAGATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAAGATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA3CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
Sample Output
no significant commonalitiesAGATACCATCATCAT
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;char str[15][100];int next[100];void getnext(char *s1){ int j = 0, k = -1; int len = strlen(s1); next[0] = -1; while(j < len){ if(k == -1 || s1[j] == s1[k]){ ++j; ++k; next[j] = k; } else k = next[k]; } return ;}bool kmp(char *s1, char *s2){ int len1 = strlen(s2); int len2 = strlen(s1); getnext(s1); int i = 0, j = 0; while(i < len1){ if(j == -1 || s1[j] == s2[i]){ ++i; ++j; } else j=next[j]; if(j == len2) return true; } return false;}int main(){ int T; scanf("%d", &T); char temp[100]; char sum[100]; while(T--){ int n; scanf("%d", &n); for(int i = 0; i < n; ++i) scanf("%s", str[i]); int len = strlen(str[0]); memset(sum, '\0', sizeof(sum)); for(int i = 0; i < len; ++i){//枚举串的起点 int ans = 0; for(int j = i; j < len; ++j){//枚举串的终点 temp[ans++] = str[0][j];//存储新的串 temp[ans] = '\0'; int flag = 1; for(int k = 1; k < n; ++k){//新的串和str[]匹配 if(!kmp(temp, str[k])){//匹配失败 flag = 0; break; } } if(flag){//匹配成功 //最长公共子串而且字典序最小 if(strlen(temp) > strlen(sum)) strcpy(sum, temp); else if(strlen(temp)==strlen(sum) && strcmp(temp, sum) < 0) strcpy(sum, temp); } } } if(strlen(sum) < 3) printf("no significant commonalities\n"); else printf("%s\n", sum); } return 0;}
1 0
- POJ 3080 Blue Jeans 暴力枚举+KMP
- POJ 3080 Blue Jeans kmp+暴力枚举
- poj 3080 Blue Jeans 【KMP 暴力枚举】
- POJ 3080--Blue Jeans【KMP && 暴力枚举】
- POJ 3080 Blue Jeans(暴力枚举+kmp)
- POJ 3080 Blue Jeans (KMP+暴力枚举)【模板】
- [KMP或者暴力]POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans KMP+暴力
- poj 3080 Blue Jeans (kmp暴力)
- POJ 3080 Blue Jeans (KMP || 暴力)
- poj 3080 Blue Jeans 【kmp+暴力】
- poj 3080 Blue Jeans kmp+枚举
- POJ 3080 Blue Jeans(KMP+枚举)
- KMP+枚举 POJ-3080 Blue Jeans
- (POJ 3080)Blue Jeans 枚举 + KMP
- POJ 3080 Blue Jeans(暴力枚举+KMP 类似POJ 3450)
- POJ 题目3080 Blue Jeans(KMP+暴力)
- POJ 3080 Blue Jeans——暴力 + kmp
- const 用法全面解析
- 黑马程序员------线程1(小结)
- HDU 3790 最短路径问题【最短路 dijkstra 双权值】
- [笔记][Java7并发编程实战手册]3.3 资源的多副本并发访问控制Semaphore
- 利用opencv源码和vs编程序训练分类器haartraining.cpp
- POJ 3080--Blue Jeans【KMP && 暴力枚举】
- 《断舍离》笔记一
- java中String的常用方法
- 数据库的基本命令及使用
- 关于System.Convert那些事
- 每日五题(mybatis)
- HDOJ 1869 六度分离(最短路径,dijkstra算法,SPFA邻接表,floyd算法)
- J114 8/17
- Linux 网卡驱动学习(七)(MAC 与 IP)