最近审题老是一错再错,Orz

题目中说求一个Hamming值总和最小的字符串,而不是从所给字符中找一个最小的

这样的话,我们逐列处理,所求字符串当前位置的字符应该是该列中出现次数最多其次ASCII值最小的

代码有点挫了,if语句太多了

 //#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; char gene[][], ans[];
int num[]; int main(void)
{
#ifdef LOCAL
freopen("3602in.txt", "r", stdin);
#endif int T;
scanf("%d", &T);
while(T--)
{
int n, m, hamming = ;
scanf("%d%d", &n ,&m);
for(int i = ; i < n; ++i)
scanf("%s", gene[i]);
for(int i = ; i < m; ++i)
{
int Max = ;
for(int j = ; j < ; ++j) num[j] = ;
for(int j = ; j < n; ++j)
{
if(gene[j][i] == 'A') ++num[];
if(gene[j][i] == 'C') ++num[];
if(gene[j][i] == 'G') ++num[];
if(gene[j][i] == 'T') ++num[];
}
for(int j = ; j < ; ++j)
if(num[j] > num[Max])
Max = j;
if(Max == ) ans[i] = 'A';
if(Max == ) ans[i] = 'C';
if(Max == ) ans[i] = 'G';
if(Max == ) ans[i] = 'T';
hamming += num[] + num[] + num[] + num[] - num[Max];
}
ans[m] = '\0';
printf("%s\n%d\n", ans, hamming);
}
return ;
}

代码君

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 (暴力枚举)

    题意:给定m个长度为n的DNA序列,求一个最短的DNA序列,使得总Hamming距离最小. Hamming距离等于字符不同的位置个数. 析:看到这个题,我的第一感觉是算时间复杂度,好小,没事,完全可以 ...

  3. LA 3602 - DNA Consensus String 枚举

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

  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. Unity--截取屏幕任意区域

    原地址:http://blog.csdn.net/tanmengwen/article/details/8501612 void Update () { if(Input.GetKeyDown(Key ...

  2. LA 3713

    The Bandulu Space Agency (BSA) has plans for the following three space missions: Mission A: Landing ...

  3. POJ 2181

    #include <iostream> #include <cstdio> #include <cmath> #define MAXN 150005 #includ ...

  4. CamShift算法

    拟采用的方法,CamShift算法,即"Continuously Apative Mean-Shift"算法,是一种运动跟踪算法.它主要通过视频图像中运动物体的颜色信息来达到跟踪的 ...

  5. sizeof学习理解

    以下内容转自: http://www.cnblogs.com/ComputerG/archive/2012/02/02/2335611.html 博问 闪存 首页 新随笔 联系 管理 随笔- 72  ...

  6. 传入sql数组字符串,输出table

    CREATE function [dbo].[split](@aString varchar(),@pattern varchar()) returns @temp table([Sid] [, ) ...

  7. cojs QAQ的图论题 题解报告

    话说这个题目应该叫做 斯特林数的逆袭 QAQ 先说一说部分分的算法 1.n<=5 直接暴力搜索就可以了 2.k=0的时候不难发现任意一张图的价值都是n,问题转化为计算有多少种图,显然是2^C(n ...

  8. Qt之图形(Source和Dest相互覆盖的取舍,真的很方便)

      源码 ... painter.drawImage(0, 0, destinationImage); painter.setCompositionMode(QPainter::Composition ...

  9. Hibernate笔记——缓存机制详细分析

    原文:http://www.cnblogs.com/xiaoluo501395377/p/3377604.html ========================================== ...

  10. React getInitialState desc

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...