题意:给定m个长度为n的DNA序列,求一个最短的DNA序列,使得总Hamming距离最小。

Hamming距离等于字符不同的位置个数。

析:看到这个题,我的第一感觉是算时间复杂度,好小,没事,完全可以暴力,只要对每个串的同一个位置,

都选出现最多的,如果有一样的选ASIIC码小的(因为要求字典序小)。然后记录最字符和Hamming距离即可。

代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector> using namespace std;
const int maxn = 1000 + 10;
char s[55][maxn];
char ans[maxn]; int main(){
int n, T, m, d, mm; cin >> T;
while(T--){
scanf("%d %d", &m, &n);
for(int i = 0; i < m; ++i)
scanf("%s", s[i]); d = 0;
for(int i = 0; i < n; ++i){
int cnta = 0, cntc = 0, cntg = 0, cntt = 0;
mm = 0;
for(int j = 0; j < m; ++j){
if('A' == s[j][i]) ++cnta;
else if('C' == s[j][i]) ++cntc;
else if('G' == s[j][i]) ++cntg;
else if('T' == s[j][i]) ++cntt;
}
mm = max(mm, cnta); mm = max(mm, cntc);//查找谁最多多
mm = max(mm, cntg); mm = max(mm, cntt);
if(mm == cnta){ ans[i] = 'A'; d += cntc; d += cntg; d += cntt; }//不同位置加和
else if(mm == cntc){ ans[i] = 'C'; d += cnta; d += cntg; d += cntt; }
else if(mm == cntg){ ans[i] = 'G'; d += cntc; d += cnta; d += cntt; }
else if(mm == cntt){ ans[i] = 'T'; d += cntc; d += cntg; d += cnta; }
}
ans[n] = '\0';//加结束符 printf("%s\n%d\n", ans, d);
}
return 0;
}

LA 3602 DNA Consensus String (暴力枚举)的更多相关文章

  1. 贪心水题。UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing

    UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { ; ){ ; ) r ...

  2. LA 3602 - DNA Consensus String 枚举

    原题地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  3. LA 3602 DNA Consensus String

    最近审题老是一错再错,Orz 题目中说求一个Hamming值总和最小的字符串,而不是从所给字符中找一个最小的 这样的话,我们逐列处理,所求字符串当前位置的字符应该是该列中出现次数最多其次ASCII值最 ...

  4. uvalive 3602 DNA Consensus String

    https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序 ...

  5. UVa 3602 - DNA Consensus String 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  6. uva1368 DNA Consensus String

    <tex2html_verbatim_mark> Figure 1. DNA (Deoxyribonucleic Acid) is the molecule which contains ...

  7. DNA Consensus String

    题目(中英对照): DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It co ...

  8. 紫书第三章训练1 E - DNA Consensus String

    DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of ...

  9. uva 1368 DNA Consensus String

    这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串. 我的思路就是求每一列每 ...

随机推荐

  1. vue深入了解组件——组件注册

    一.组件名 在注册一个组件的时候,我们始终需要给它一个名字.比如在全局注册的时候我们已经看到了: Vue.component('my-component-name', { /* ... */ }) J ...

  2. HIBERNATE知识复习记录2-继承关系

    发现了一篇和我类似的学习尚硅谷视频写的文章,内容如下,比我说的详细全面,可以看一下: [原创]java WEB学习笔记87:Hibernate学习之路-- -映射 继承关系(subclass , jo ...

  3. 一个取消事件的简单js例子(事件冒泡与取消默认行为)

    先上代码: <div id='outer' onclick='alert("我是outer")'> <div id="middle" oncl ...

  4. 详述Oracle RAC的五大优势及其劣势

    不同的集群产品都有自己的特点,RAC的特点包括如下几点: ·双机并行.RAC是一种并行模式,并不是传统的主备模式.也就是说,RAC集群的所有成员都可以同时接收客户端的请求. ·高可用性.RAC是Ora ...

  5. js 获取字符串的 像素 宽度 ----字符串格式化输出

    function getLenPx(str, font_size) { var str_leng = str.replace(/[^\x00-\xff]/gi, 'aa').length; retur ...

  6. docker 配置远程访问

    系统: centos 7 Docker version 1.12.6 yum 安装的  #yum install docker docker server在192.168.111.120上 # vim ...

  7. Web服务技术协议:REST与SOAP

    Web服务技术就有SOAP(Simple Object Access Protocol,简单对象访问协议)和REST(Representational State Transfer,表示性状态转移) ...

  8. War(最短路+最大流)

    War http://acm.hdu.edu.cn/showproblem.php?pid=3599 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  9. ES5之defineProperty

    一 概述 Object.defineProperty() 方法会直接在一个对象上定义一个新属性,或者修改一个对象的现有属性, 并返回这个对象. 对象里目前存在的属性描述符有两种主要形式:数据描述符和存 ...

  10. .NET中的文件IO操作实例

    1.写入文件代码: //1.1 生成文件名和设置文件物理路径 Random random = new Random(DateTime.Now.Millisecond); ); string Physi ...