这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串。

我的思路就是求每一列每个基因A、C、G、T的数量,找到最大值,最大值可能不止一个,但是锁定字典序最小的那个为所求字符串当前列的值,求解实例如下所示

TATGATAC
TAAGCTAC
AAAGATCC
TGAGATAC
TAAGATGT

对于上述字符串,第一列A,C,G,T的值分别为1,0,0,4,可见最大值为4,说明当前列到每个字符串之和最短的是T字母,所以得到所求字符串第一个字母为T,同样的方法求得剩下所有字符,最后得到所求字符串为TAAGATAC,而 consensus error的值等于每一列的值相加,第一列,最大值为4,那么consensus error在第一列的值为m-4=5-4=1;所以consensus error的值为1+1+1+0+1+0+2+1=7,具体实现代码如下:

#include<algorithm>
#include<cstring>
#include<cstdio>
#include<iostream>
#define len 1010
#define M 55
using namespace std; char dna[M][len];
int gene[];
int m, n; int main()
{
int T;
int minSum;
char res[];
cin >> T;
while (T--) {
cin >> m >> n;
minSum = ;
for (int i = ;i < m;i++)
cin >> dna[i];
int j = ;
for (j = ;j < n;j++) {
memset(gene, , sizeof(gene));
for (int i = ;i < m;i++) {
switch (dna[i][j]) {
case 'A':gene[]++;break;
case 'C':gene[]++;break;
case 'G':gene[]++;break;
case 'T':gene[]++;break;
default:break;
}
}
int max = ;
for (int i = ;i < ;i++) {
if (gene[i] > max) {
max = gene[i];
switch (i) {
case :res[j] = 'A';break;
case :res[j] = 'C';break;
case :res[j] = 'G';break;
case :res[j] = 'T';break;
default:break;
}
}
}
minSum += m-max;
}
res[j] = '\0';
cout << res << endl;
cout << minSum << endl; }
return ;
}

uva 1368 DNA Consensus String的更多相关文章

  1. 【每日一题】UVA - 1368 DNA Consensus String 字符串+贪心+阅读题

    https://cn.vjudge.net/problem/UVA-1368 二维的hamming距离算法: For binary strings a and b the Hamming distan ...

  2. UVa 3602 - DNA Consensus String 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  3. 贪心水题。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 ...

  4. uva1368 DNA Consensus String

    <tex2html_verbatim_mark> Figure 1. DNA (Deoxyribonucleic Acid) is the molecule which contains ...

  5. DNA Consensus String

    题目(中英对照): DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It co ...

  6. 紫书第三章训练1 E - DNA Consensus String

    DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of ...

  7. 【习题 3-7 UVA - 1368 】DNA Consensus String

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举每一位字母是什么. 从小到大枚举. 然后计算每一位的总贡献是多少. 取最小的那个输出. [代码] #include <bi ...

  8. DNA Consensus String UVA - 1368

    题目链接:https://vjudge.net/problem/UVA-1368 题意:给出一组字符串,求出一组串,使与其他不同的点的和最小 题解:这个题就是一个点一个点求,利用桶排序,求出最多点数目 ...

  9. uvalive 3602 DNA Consensus String

    https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序 ...

随机推荐

  1. [深入Python]Python的私有变量

    Python没有真正的私有变量.内部实现上,是将私有变量进程了转化,规则是:_<类名><私有变量> 下面的小技巧可以获取私有变量: class Test(object): de ...

  2. 2014-04-09 互联网Web安全职位面试题目汇总

    Domain 解释一下同源策略 同源策略,那些东西是同源可以获取到的 如果子域名和顶级域名不同源,在哪里可以设置叫他们同源 如何设置可以跨域请求数据?jsonp是做什么的? Ajax Ajax是否遵循 ...

  3. linux上安装php+gd扩展

    515 cd zlib-1.2.3 516 ./configure --prefix=/usr/local/zlib2 517 make && make install 518 cd ...

  4. Classes

    Class Organization Following the standard Java convention, a class should begin with a list of varia ...

  5. 无线网络的切换bat

    内网外网都是无线,切换起来麻烦,做了两个个bat(注意,切换网络的时候有延时,就点两次). -------------------下面的是切换到内网-------------------------- ...

  6. vim编辑下Python2.0自动补全

    Python自动补全有vim编辑下和python交互模式下,下面分别介绍如何在这2种情况下实现Tab键自动补全. 一.vim python自动补全插件:pydiction 可以实现下面python代码 ...

  7. js 设置Cookie 在PHP中读取(大师手法)

    设置Cookie时要把一个json整体放入Cookie而不是单独放入,影响效率. var Cookies = {};     /**     * 设置Cookies     */         va ...

  8. WOJ-1097

    Description JYY has placed N bombs on the plane. We assume that the firepower area of each bomb is c ...

  9. 2015GitWebRTC编译实录11

    2015.07.21 ilbc 编译通过注意有几个win32打头的文件,其实都是要编进去的[429/1600 ] CC obj ilbc.abs_quant.o[430/1600 ] CXX obj ...

  10. UDP信息接收与发送

    转载:http://www.cnblogs.com/sunev/archive/2012/08/08/2627247.html 一.摘要 总结基于C#的UDP协议的同步通信. 二.实验平台 Visua ...