链接:

http://poj.org/problem?id=3080

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#problem/E (密码0817)

Blue Jeans
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 14544   Accepted: 6478

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 算法, 看了一下不是很懂, 感觉是解决字符串匹配的问题,不知道理解是否正确,先粘个代码学习一下

这个就是个暴力加KMP, 子串的长度要大于等于3,相同长度的要字典序最大的

代码:

#include<stdio.h>
#include<string.h> #define N 100 char s[N][N];
int next[N]; void GetNext(char s[])
{
int i=, j=-, n=strlen(s);
next[] = -; while(i<n)
{
if(j==- || s[i]==s[j])
next[++i] = ++j;
else
j = next[j];
}
}
bool KMP(char a[], char s[])
{
int i=, j=;
int Na=strlen(a), Ns=strlen(s); while(i<Na)
{
while(j==- || (a[i]==s[j] && i<Na))
i++, j++; if(j==Ns) return true; j = next[j];
}
return false;
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int i, j, len, m, MaxLen = ;
char ans[N]="Z"; scanf("%d", &m); for(i=; i<m; i++)
scanf("%s", s[i]); for(len=; len>=; len--)
for(i=; i<=MaxLen-len; i++) ///枚举第一个串的所有子串
{
char b[N]={}; strncpy(b, s[]+i, len);
GetNext(b); for(j=; j<m; j++)
if(KMP(s[j], b)==false)
break; if(j==m && strcmp(ans, b)>)
strcpy(ans, b); if(ans[]!='Z' && i==MaxLen-len)
i=, len=; ///跳出循环
} if(ans[] == 'Z')
printf("no significant commonalities\n");
else
printf("%s\n", ans);
}
return ;
}

(字符串 KMP)Blue Jeans -- POJ -- 3080:的更多相关文章

  1. Match:Blue Jeans(POJ 3080)

    DNA序列 题目大意:给你m串字符串,要你找最长的相同的连续字串 这题暴力kmp即可,注意要按字典序排序,同时,是len<3才输出no significant commonalities #in ...

  2. Blue Jeans - POJ 3080(多串的共同子串)

    题目大意:有M个串,每个串的长度都是60,查找这M个串的最长公共子串(连续的),长度不能小于3,如果同等长度的有多个输出字典序最小的那个.   分析:因为串不多,而且比较短,所致直接暴力枚举的第一个串 ...

  3. Blue Jeans POJ 3080 寻找多个串的最长相同子串

    Description The Genographic Project is a research partnership between IBM and The National Geographi ...

  4. Blue Jeans - poj 3080(后缀数组)

    大致题意: 给出n个长度为60的DNA基因(A腺嘌呤 G鸟嘌呤 T胸腺嘧啶 C胞嘧啶)序列,求出他们的最长公共子序列 使用后缀数组解决 #include<stdio.h> #include ...

  5. POJ 3080 Blue Jeans (求最长公共字符串)

    POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...

  6. POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)

    Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20966   Accepted: 9279 Descr ...

  7. POJ 3080 Blue Jeans (字符串处理暴力枚举)

    Blue Jeans  Time Limit: 1000MS        Memory Limit: 65536K Total Submissions: 21078        Accepted: ...

  8. POJ Blue Jeans [枚举+KMP]

    传送门 F - Blue Jeans Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  9. POJ 3080 Blue Jeans(Java暴力)

    Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...

随机推荐

  1. bzoj 3144 [Hnoi2013]切糕——最小割

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3144 一根纵轴上切一个点,可以把一根纵轴上的点连成一串来体现.自己的写法是每个点连向前一个点 ...

  2. Java与SQL Server, MySql, Oracle, Access的连接方法以及一些异常解决

    Java与SQL Server, MySql, Oracle, Access的连接方法以及一些异常解决 I. 概述 1.1 JDBC概念 JDBC(Java Database Connectivity ...

  3. Java获取Resource目录下的文件

    工程结构: 有两种方式: Java代码中的类,要获取Resource资源文件目录下文件 绝对路径寻址 String s1 = this.getClass().getResource("/te ...

  4. (转)powerdesigner 生成sql脚本使用的设置

    本文转载自:http://blog.163.com/lizhihaoo@126/blog/static/103121661201036171115/ 1. 生成sql脚本的时候,提示"con ...

  5. 第5课 Qt Creator工程介绍

    1. QT Creator工程管理(一个工程包含不同类型的文件) (1).pro项目文件 (2).pro.user用户配置描述文件 (3).h头文件 (4).cpp源文件 (5).ui界面描述文件 ( ...

  6. fireDAC oracle

    copy 4 files to D:\oracleapp\Administrator\product\11.2.0\client_1\BIN setup win 64 bit client .down ...

  7. Spring Boot日志集成

    Spring Boot日志框架 Spring Boot支持Java Util Logging,Log4j2,Lockback作为日志框架,如果你使用starters启动器,Spring Boot将使用 ...

  8. Java 目标

    Java 技术 其次掌握的技能树主要有三个方面:第一个是基础,比如对集合类,并发包,IO/NIO,JVM,内存模型,泛型,异常,反射,等有深入了解,最好是看过源码了解底层的设计.比如一般面试都会问Co ...

  9. 分享 - 普通程序员如何转向AI方向

    原作者:计算机的潜意识 原文链接,内容稍有改动,侵删 1. 目的2. AI领域简介3. 学习方法4. 学习路线 0) 领域了解1) 知识准备2) 机器学习3) 实践做项目4) 深度学习5) 继续机器学 ...

  10. 图片上传jQuery插件(兼容IE8)

      图片上传jQuery插件(兼容IE8) 代码来源 :https://github.com/zilan93/uploadImg   html <!DOCTYPE html> <ht ...