题意:给定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. Java synchronized(this)锁住的是什么

    synchronized锁住的是括号里面的对象,而不是代码. 对于非static的synchronized方法,锁的就是对象本身,也就是this.

  2. this指针的调整

    我们先来看一段代码: #include <iostream> using namespace std; class A { public: int a; A( ) { printf(&qu ...

  3. Linux多网卡负载均衡 : bond

    USERCTL=no/yes 普通用户是否可以关闭或启用网关 -------------------------------- 在这介绍的Linux双网卡绑定实现就是使用两块网卡虚拟成为一块网卡,这个 ...

  4. Delphi 解析系统环境变量

    // http://www.outofmemory.cn function ExpandEnvironment(const strValue: string): string; var chrResu ...

  5. rook 记录

    更改rook 集群的配置 https://github.com/rook/rook/blob/master/design/cluster-update.md rook集群升级流程 https://ro ...

  6. Containerpilot 配置文件 之 consul

    Consul ContainerPilot使用Hashicorp的consul在作为服务的容器中注册工作. Watches查询consul找出其他服务的状态. Client configuration ...

  7. [udemy]WebDevelopment_How the Internet Works

    Browsing the web Enter google.com, who is this google.com This question gets asked all the way down ...

  8. 10-多写一个@Autowired导致程序崩了

    再是javaweb实验六中,是让我们改代码,让它跑起来,结果我少注释了一个,导致一直报错,检查许久没有找到,最后通过代码替换逐步查找,才发现问题.

  9. vmware14中安装centos7并使用docker发布spring-boot项目

    1.vmare中centos7安装(同一路由器无线网络下) 1.1选择桥接模式 1.2修改配置文件 vi /etc/sysconfig/network-scripts/ifcfg-ens33(这里不一 ...

  10. MVC加载部分视图Partial

    加载部分视图的方法:Partial() .RenderPartial() . Action() .RenderAction() . RenderPage() partial 与 RenderParti ...