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

我的思路就是求每一列每个基因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. Android常见控件— — —AlertDialog

    package com.example.uiwidgettest2; import android.app.Activity;import android.app.AlertDialog;import ...

  2. ubuntu下搭建samba服务器

    samba是用于linux和windows下文件共享的协议 首先,更新源并安装samba sudo apt-get update sudo apt-get install samba 然后创建一个共享 ...

  3. Unparsed aapt error(s)! Check the console for output解决方法

    在Eclipse平台进行Android 应用开发时,编辑,修改或增删 res/下资源文件时有时会遇到如下错误提示:“Unparsed  aapt error(s)! Check the console ...

  4. angular插件合集

    图片视频类 angular-maxonry 图片墙效果插件,可以将图片组织成类似于瀑布流的效果,依赖于jQuery.imageloaded和Masonry angular-deckgrid 另一个照片 ...

  5. Android 布局优化

    转载自stormzhang的博客:http://stormzhang.com/android/2014/04/10/android-optimize-layout/ < include /> ...

  6. Golang Clearing slice

    //first method : slice = nil // second method : slice = slice[0:0] Source page : https://www.socketl ...

  7. Python 决策树的构造

    上一节我们学习knn,kNN的最大缺点就是无法给出数据的内在含义,而使用决策树处理分类问题,优势就在于数据形式非常容易理解. 决策树的算法有很多,有CART.ID3和C4.5等,其中ID3和C4.5都 ...

  8. 深入浅出数据分析 Head First Data Analysis Code 数据与代码

    <深入浅出数据分析>英文名为Head First Data Analysis Code, 这本书中提供了学习使用的数据和程序,原书链接由于某些原因不 能打开,这里在提供一个下载的链接.去下 ...

  9. CentOS 6.6 中中文输入法设置

    排版比较乱你,参见 https://www.zybuluo.com/Jpz/note/144597 Linux开发环境配置 安装完系统之后,我们需要设置中文输入法,中文输入法是系统自带的,设置步骤如下 ...

  10. 在yii中使用多个数据库

    背景: 对于一个大公司拥有多个分公司的应用场景下,我们通常需要配置多个sub-database(子数据库)来存储不同的数据纪录. 配置步骤: 1.在application骨架里面的主配置文件main. ...