题意:给定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. urllib 和urllib2 模块使用简例

    一.最简单的使用 import urllib,urllib2 response = urllib2.urlopen("https://www.baidu.com") print r ...

  2. Windows自带的端口转发工具netsh使用方法_DOS/BAT

    Windows自带的端口转发工具netsh使用方法_DOS/BAT   作者:用户 来源:互联网 时间:2017-02-22 17:24:30 netsh 端口转发 摘要: 下面的代码在windows ...

  3. CSS 折角效果

    1 <style type="text/css"> .div1 { width: 200px; height: 200px; background-color: #ff ...

  4. 使用JS伪造Post请求

    [使用JS伪造Post请求] 提到伪造Post请求,首先想到的是构造HTTP包.但实际上有一种更简单的方法,构造HTML FORM表单,使用js进行提交.如下:

  5. SO\PR回写的数据如下

    insert into OUT_ORDER_RES ---JAVA FOR PR ) as LGORT ,'SAPRFC' as ERNAM,out_pr.due_datetime,out_pr.so ...

  6. Android中WebView使用全解

    开始 在Android系统中内嵌的WebKit,这是一个浏览器内核,它帮助着我们可以浏览网页.在实际开发中,如果你想让你的App能够访问网页,那就需要用到WebView这个控件. 如何使用? 其实使用 ...

  7. cf-Round542-Div2-C(暴力+DFS)

    题目链接:http://codeforces.com/contest/1130/problem/C 思路: 利用DFS搜索(r1,c1)和(r2,c2)可到达的点的集合,分别存在a1,a2中,若a1= ...

  8. numpy.unpackbits()

    numpy.unpackbits numpy.unpackbits(myarray, axis=None) Unpacks elements of a uint8 array into a binar ...

  9. Time range (447392) for take 'Take 001' is larger than maximum allowed(100000).

    http://www.cnblogs.com/lopezycj/archive/2012/05/16/unity3d_tuchao.html https://forum.unity3d.com/thr ...

  10. 'wmic' 不是内部或外部命令,也不是可运行的程序 解决方法

    在环境变量中查看变量名Path下的变量值是否有以下讯息? 如没有复制(Ctrl+C).黏贴(Ctrl+V)→确定即可. %SystemRoot%;%SystemRoot%\system32;%Syst ...