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 ...
随机推荐
- java 八种基本数据类型
- 查找轮廓(cv2.findCountours函数)
1.输入为二值图像,黑色为背景,白色为目标 2.该函数会修改原图像,因此若想保留原图像在,则需拷贝一份,在拷贝图里修改. 一.查找轮廓 cv2.findContours() 三个输入参数:输入图像(二 ...
- linux CPU动态调频【转】
转自:https://www.xuebuyuan.com/2185926.html 针对sep4020的linux低功耗研究也有一段时间了,基本把低功耗的实现方式想清楚了(主要分成机制和策略),这段时 ...
- mac配置supervisor
mac配置supervisor 安装 brew install supervisor 启动 一种是手动 supervisord -c /usr/local/etc/supervisord.ini 让s ...
- javascript面向对象学习
1.this指向问题,指向的是当前的方法属于谁,当前的方法属于谁就指向谁!! 例子: oDiv.onclick = function () { this指向的是oDiv,因为这个方法属于oDiv } ...
- 微信小程序-动态设置背景色navigationBarBackgroundColor的值
查看API: wx.setNavigationBarColor(OBJECT) 代码: wx.setNavigationBarColor({ frontColor: '#ffffff', // 必写项 ...
- 如何将Tomcat添加到服务中【笔记】
tomcat中自带有添加服务的批处理,所以只需要从命令行界面进入到需要添加到服务的tomcat目录中,执行service.bat install 命令就可以自动添加默认名称的tomcat服务了. 该批 ...
- QTableWidget
1.QTableWidget继承自QTableView. QSqlTableModel能与QTableView绑定,但不能于QTableWidget绑定. QTableWidget是QTableVi ...
- 通过flask实现web页面简单的增删改查bootstrap美化版
通过flask实现web页面简单的增删改查bootstrap美化版 项目目录结构 [root@node1 python]# tree -L 2 . ├── animate.css ├── fileut ...
- Linux命令之top、ulimit、free
1.[ulimit命令] ulimit命令用来限制系统用户对shell资源的访问. 假设有这样一种情况,当一台 Linux 主机上同时登陆了 10 个人,在系统资源无限制的情况下,这 10 个用户同时 ...