最近审题老是一错再错,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. 索引服务混战ASP.NET――微软的又一个隔离墩

    话说月初笔者在华山之巅搞定了ASP.NET一起莫名奇妙的异常,自此之后和公主过着…嘟--,不好意思,书都看杂了,串了台了.好,咱们闲言少叙,书归正传. 自从上次解决了由调试文件库引起的ASP.NET执 ...

  2. HDU 2843 I Will Win(概率题?,怨念颇深,简单)

    题目 真不想说什么,,,这神题真讨厌,,,多校的.. //又是一道神题... #include<stdio.h> #include<string.h> //最大公约数 int ...

  3. GCD的简单封装

    扩展: dispatch_block_t :无参数block,使用起来很简单 下载链接:http://pan.baidu.com/s/1bndN6Yb    ]; }     //定时器 - (voi ...

  4. POJ 1969

    #include <iostream> #include <cmath> using namespace std; int main() { //freopen("a ...

  5. 浏览器的CSS各种hack,大汇总

    对着IE久了也有感觉了,在win10出新浏览器以及中国的IE6+用户没有普及新的浏览器前IE还是个坑,所以hack这东西还是要掌握一点的.不废话直接贴图 记得之前在项目里面针对IE6的hack是这样写 ...

  6. asp.net跳转页面的三种方法比较

    目前,对于学习asp.net的很多朋友来讲,实现跳转页面的方法还不是很了解.本文将为朋友们介绍利用asp.net跳转页面的三种方法,并对其之间的形式进行比较,希望能够对朋友们有所帮助. ASP.NET ...

  7. 怎么修改mysql密码

    1.用root 进入mysql后mysql>set password =password('你的密码');mysql>flush privileges; 2.使用GRANT语句 mysql ...

  8. 实践Oracle与DB2区别及问题解决

    实践Oracle与DB2区别及问题解决 项目进入开发阶段的时候,为了方便,一直使用Oracle数据库进行开发, 所以很多sql语句都是在oracle能正常创建的,后期由于项目中嵌入了IBM的产品及其他 ...

  9. oracle记录解锁

    oracle 怎样查一个表中的记录是否被锁住了   怎么查询一个数据库中有几个表引用了其中某个特定表的主键做为其外键的select t.table_name from user_constraints ...

  10. Redis通用操作(适用于String,Hash,链表等)

    keys pattern 查询相应的key 在redis里,允许模糊查询key 有3个通配符 *, ? ,[] *: 通配任意多个字符 ?: 通配单个字符 []: 通配括号内的某1个字符 redis ...