poj 3080 Blue Jeans
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10243 | Accepted: 4347 |
Description
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
- 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
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
题目大意就是求m个子串的最长公共子串,如果最长公共子串长度小于3,则输出 no significant commonalities,如果有多个长度相同的,则输出字典序比较小的
方法比较暴力,就是先求第一个和第二个的公共子序列,然后把所有的子序列存下来,放到一个set里,然后再从set里拿出1,2的子序列和第三个序列比,再把求得的子序列继续扔到set里,再和下一个比,直到最后一个,set里剩下的就是所有的公共子序列了,这里提一点,上面所有的比较过程中如果某个序列长度小于3了,就直接丢掉了,不会再计算,最后在set里找一个字典序最小的
#include<stdio.h>
#include<string.h>
#include<set>
#include<string>
using namespace std; set<string> ans;
char dna[11][61];
void cmp_sub(int m)
{
int i, k, l, f;
char temp[61];
char sub[61];
int total = ans.size();
set<string>::iterator j, prev;
for(i = 2; i < m; i++)
{
for(j = ans.begin(); j != ans.end();)
{ int len = (*j).length();
int count = 0;
int max = -1;
bool flag = 0;
for(k = 0; k < 60 && flag == 0; k++)
{ for(l = 0; l < len && flag == 0; l++)
{
if(dna[i][k] == (*j)[l])
{
count = 1;
sub[0] = dna[i][k];
for(f = 1; dna[i][k + f] == (*j)[l + f] && f + l < len && dna[i][k + f]; f++)
{
count++;
sub[f] = dna[i][k + f];
}
if(count >= 3)
{
max = count;
sub[f] = 0;
strcpy(temp, sub);
ans.insert(sub);
}
if(strcmp((*j).c_str(), temp) == 0 )
{
flag = 1;
break;
}
}
}
}
if(flag == 0)
{
prev = j;
j++;
ans.erase(prev); if(strlen(temp) > 2)
ans.insert(temp);
}
else
j++;
}
}
}
void find_sub()
{
int i, j, k;
char sub[61];
int total = 0;
int count;
string str;
for(i = 0; i < 60; i++)
{
for(j = 0; j < 60; j++)
{
if(dna[0][i] == dna[1][j])
{
count = 1;
sub[0] = dna[0][i];
for(k = 1; dna[0][i + k] == dna[1][j + k] && dna[0][i + k] && dna[1][j + k]; k++)
{
sub[k] = dna[0][k + i];
count++;
}
if(count >= 3)
{
sub[k] = 0;
str = sub;
ans.insert(str);
}
}
}
}
}
int main()
{
// freopen("t//t.txt", "r", st//n);
int n, m;
scanf("%d", &n);
while(n--)
{
scanf("%d", &m);
ans.clear();
int i;
getchar();
for(i = 0; i < m ;i++)
gets(dna[i]);
find_sub();
if(ans.size() == 0)
{
printf("no significant commonalities\n");
continue;
}
cmp_sub(m);
set<string>::iterator j, mark;
int max = 0;
for(j = ans.begin(); j != ans.end(); j++)
{
// printf("%d\n%d\n%d\n%d\n",(*j).length(), max, (((*j).length()) > max), ((*j).length() > 2)) ;
if(((*j).length() > max) && ((*j).length() > 2))
{
max = (*j).length();
mark = j;
}
}
if(max > 2)
{
printf("%s\n", (*mark).c_str());
}
else
printf("no significant commonalities\n");
}
return 0;
}
poj 3080 Blue Jeans的更多相关文章
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- POJ 3080 Blue Jeans (字符串处理暴力枚举)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21078 Accepted: ...
- 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 解题报告
题目链接:http://poj.org/problem?id=3080 该题属于字符串处理中的串模式匹配问题.题目要求我们:给出一个DNA碱基序列,输出最长的相同的碱基子序列.(保证在所有的序列中都有 ...
- poj 3080 Blue Jeans(水题 暴搜)
题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...
- POJ 3080 Blue Jeans(后缀数组+二分答案)
[题目链接] http://poj.org/problem?id=3080 [题目大意] 求k个串的最长公共子串,如果存在多个则输出字典序最小,如果长度小于3则判断查找失败. [题解] 将所有字符串通 ...
- POJ 3080 Blue Jeans 后缀数组, 高度数组 难度:1
题目 http://poj.org/problem?id=3080 题意 有m个(2<=m<=10)不包含空格的字符串,长度为60个字符,求所有字符串中都出现过的最长公共子序列,若该子序列 ...
- poj 3080 Blue Jeans【字符串处理+ 亮点是:字符串函数的使用】
题目:http://poj.org/problem?id=3080 Sample Input 3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCA ...
随机推荐
- oracle ORA-01747(系统保留关键字)user.table.column, table.column 或列说明无效 hibernate映射oracle保留关键字
1.查询系统关键 select * from v$reserved_words 确认你使用的是否为关键字: select * from v$reserved_words w where w.KEYWO ...
- mysql的text的类型注意
不要以为text就只有一种类型! Text也分为四种类型:TINYTEXT.TEXT.MEDIUMTEXT和LONGTEXT 其中 TINYTEXT 256 bytes TEXT 65,535 byt ...
- MySQL 利用SQL线程对Binlog操作(转)
背景: 对于MySQL的binlog的查看都是用其自带的工具mysqlbinlog进行操作的,其实还有另一个方法来操作binlog,就是Replication中的SQL线程去操作binlog,其实bi ...
- Servlet程序访问的流程
方式一: jsp: <font color="red">${ msg }</font> <form action="/personal/re ...
- java读取properties文件的内容
获得properties文件中某个key对应着的value // 路径名称 + properties的名称,不要“properties” private static final String BUN ...
- Jquery实现购物车物品数量的加减特效
今天网友翠儿在用Jquery实现购物车物品数量的加减特效的时候遇到问题来问我,我后来帮她解决了这个Jquery特效,现在把它整理出来分享给大家用,虽然功能比较简单,但是很实用. 主要包括了以下功能: ...
- SSH_框架整合5--验证用户名是否可用
SSH_框架整合5--验证用户名是否可用 1 emp-input.jsp中编写ajax验证用户名是否可用: <script type="text/javascript" SR ...
- json换行符的处理
JS端的: var s = JSON.stringify(str); var ss = s.replace(/\\n/g, "\\n") .replace(/\\'/g, &quo ...
- AWS控制台改英文
https://console.amazonaws.cn 控制台首选项->语言->英文
- android学习笔记六——Spinner
注:参考http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0105/2264.html Spinner ==> Spinner ...