POJ 3080 Blue Jeans (字符串处理暴力枚举)
Blue Jeans
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 21078 Accepted: 9340
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
题意:找出给定字符串中都存在的最长的字典序最小的子串,若长度小于3,则输出no significant commonalities,否则输出该子串
思路:按长度递增的顺序,暴力枚举每个例子的第一个字符串的子串,然后通过strstr函数该子串验证是否存在于其他字符串中,每一步记录最长的子串,最后根据题意输出
#include<iostream>
#include<string.h>
using namespace std;
char s[11][66],str[66],ans[66];
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%s",s[i]);
memset(ans,'\0',sizeof(ans));//后面求ans长度有用
for(int len=1;len<=60;len++)
{
int cnt=0;
for(int st=0;st<=60-len;st++)
{
for(int i=st;i<st+len;i++)//把一段字符串赋值给str
str[i-st]=s[0][i];
str[st+len]='\0';
int flag=1;
for(int i=1;i<n;i++)
if(!strstr(s[i],str)){//判断s[i]里面是否有str
flag=0;break;//一个不符合就退出该循环
}
if(flag)
{
cnt=1;
if(strlen(ans)<strlen(str))//取长的
strcpy(ans,str);
else if(strcmp(str,ans)<0)//取字典序小的
strcpy(ans,str);
}
}
if(!cnt)//短的都没有,长的肯定也没有
break;
}
if(strlen(ans)<3)
printf("no significant commonalities\n");
else
printf("%s\n",ans);
}
return 0;
}
POJ 3080 Blue Jeans (字符串处理暴力枚举)的更多相关文章
- POJ - 3080 Blue Jeans 【KMP+暴力】(最大公共字串)
<题目链接> 题目大意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 限制条件: 1. 最长公共串长度小于3输出 no significant co ...
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- POJ 3080 Blue Jeans(Java暴力)
Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...
- POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20966 Accepted: 9279 Descr ...
- poj 3080 Blue Jeans
点击打开链接 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10243 Accepted: 434 ...
- 【POJ 3080 Blue Jeans】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...
- POJ 3080 Blue Jeans (多个字符串的最长公共序列,暴力比较)
题意:给出m个字符串,找出其中的最长公共子序列,如果相同长度的有多个,输出按字母排序中的第一个. 思路:数据小,因此枚举第一个字符串的所有子字符串s,再一个个比较,是否为其它字符串的字串.判断是否为字 ...
- poj 3080 Blue Jeans (暴力枚举子串+kmp)
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- poj 3080 Blue Jeans【字符串处理+ 亮点是:字符串函数的使用】
题目:http://poj.org/problem?id=3080 Sample Input 3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCA ...
随机推荐
- [转] 图 + 文 + 公式 理解LSTM
转自公号“机器之心” LSTM入门必读:从入门基础到工作方式详解 长短期记忆(LSTM)是一种非常重要的神经网络技术,其在语音识别和自然语言处理等许多领域都得到了广泛的应用..在这篇文章中,Edwin ...
- Android软键盘在清单文件中所有配置含义
android:windowSoftInputMode 活动的主窗口如何与包含屏幕上的软键盘窗口交互.这个属性的设置将会影响两件事情: 1> 软键盘的状态——是否它是隐藏或显示——当活动 ...
- MFC调用libyara遇到的问题
测试结果 如果调用yara非要变成共享DLL的形式,加那么多的DLL,不如直接调用EXE文件.反而依赖vcruntime运行库的DLL会少很多... 调用libyara 调用libraya和C++调用 ...
- python中的正则表达式--re模块
参考博客:https://www.cnblogs.com/tina-python/p/5508402.html 这里说一下python的re模块即正则表达式模块,先列出其中涉及到的各种字符和模式等: ...
- mysql配置修改项
[mysqld] innodb_locks_unsafe_for_binlog = 1 transaction-isolation = READ-COMMITTED 作用:防死锁 ,提高并发入库速度
- html5 - Storage 本地存储
Storage的解释 http://www.w3school.com.cn/html5/html_5_webstorage.asp 简单的理解就是: Storage 有两种: 1.localStora ...
- PHP导出MySQL数据字典 Summer-Mysql-Dic
2017年11月9日09:30:29 用 PHP 写的一个类文件, 用来导出MySQL数据字典 导出表信息; 字段信息, 索引信息 可以导出浏览器适用的样式, 也可以导出word文档 建议上线前用这个 ...
- 前端 ----关于DOM的操作的相关实例
关于DOM操作的相关案例 1.模态框案例 需求: 打开网页时有一个普通的按钮,点击当前按钮显示一个背景图,中心并弹出一个弹出框,点击X的时候会关闭当前的模态框 代码如下: <!DOCTYPE ...
- __dict__(字典的另一种用法)
class Foo(): def __init__(self): self.name=None self.age=19 self.addr='上海' @property def dict(self): ...
- nginx负载均衡后端tomcat无法加载js资源
JS或css无法完全加载 nginx的代理缓存区,默认较小导致部分文件出现加载不全的问题,比较典型的如jQuery框架,可以通过配置调整nginx的缓存区即可.主要参考proxy参数 最终完整配置如下 ...