题意:给定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. as3 连接mysql

    http://www.cnblogs.com/yili16438/archive/2011/04/23/2025936.html

  2. ansible之条件语句when

    注册变量: 变量的另一个用途是将一条命令的运行结果保存到变量中,供后面的playbook使用.例如: - hosts: webservers tasks: - shell: /usr/bin/foo ...

  3. servlet类

    一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司在其API中提供了一个servlet接口,用户若想用发一个动态web资源(即开发一个Java程序向 ...

  4. SpringDataJPA模糊查询遇到的坑

    遇到的情况:在做短信渠道管理添加时,先要去校验数据库中是否有该产线-短信类型-渠道的记录,如果存在就不添加. //在库中是否存在该记录 private boolean ifExistChannelCo ...

  5. HSTS详解

    1. 缘起:启用HTTPS也不够安全 有不少网站只通过HTTPS对外提供服务,但用户在访问某个网站的时候,在浏览器里却往往直接输入网站域名(例如www.example.com),而不是输入完整的URL ...

  6. C函数指针的用法

    1.最简单的用法: #include <cstdio> int (*p)(int);//定义一个函数指针变量p(下面的f其实是一个常量函数指针) int f(int x) { printf ...

  7. Animation.wrapMode循环模式

    WrapMode.Default:从动画剪辑中读取循环模式(默认是Once). WrapMode.Once:当时间播放到末尾的时候停止动画的播放. WrapMode.Loop:当时间播放到末尾的时候重 ...

  8. phpStudy3——往数据库中添加数据

    前言: 前边介绍了查询数据库的方法,这里介绍下往数据库中添加数据的方法. 项目需求: 用户在前端页面输入的用户名和手机号码,点击提交后后端判断手机号码是否已经存在.如果不存在,那么插入数据库到数据库, ...

  9. 安装配置Windows Live Writer做为博客客户端

    前言: 国内好些空间.博客是支持Windows Live Writer客户端的,也就是说使用Windows Live Writer不用登陆博客网站,就可以向不同的博客网站发布博客了. Windows ...

  10. CentOS日志列表

    anaconda/* 包含至少5个日志文件:anaccmda.log用于保存一般安装消息:anaconda.packaging.log用于保存包安装消息:anaconda.programJog用于调用 ...