uva 1368 DNA Consensus String
这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串。
我的思路就是求每一列每个基因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的更多相关文章
- 【每日一题】UVA - 1368 DNA Consensus String 字符串+贪心+阅读题
https://cn.vjudge.net/problem/UVA-1368 二维的hamming距离算法: For binary strings a and b the Hamming distan ...
- UVa 3602 - DNA Consensus String 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 贪心水题。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 ...
- uva1368 DNA Consensus String
<tex2html_verbatim_mark> Figure 1. DNA (Deoxyribonucleic Acid) is the molecule which contains ...
- DNA Consensus String
题目(中英对照): DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It co ...
- 紫书第三章训练1 E - DNA Consensus String
DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of ...
- 【习题 3-7 UVA - 1368 】DNA Consensus String
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举每一位字母是什么. 从小到大枚举. 然后计算每一位的总贡献是多少. 取最小的那个输出. [代码] #include <bi ...
- DNA Consensus String UVA - 1368
题目链接:https://vjudge.net/problem/UVA-1368 题意:给出一组字符串,求出一组串,使与其他不同的点的和最小 题解:这个题就是一个点一个点求,利用桶排序,求出最多点数目 ...
- uvalive 3602 DNA Consensus String
https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序 ...
随机推荐
- poj2240 floyd
//Accepted 732 KB 782 ms //floyd应用 #include <cstdio> #include <cstring> #include <ios ...
- [UIImage resizableImageWithCapInsets:]
[UIImage resizableImageWithCapInsets:]使用注意 转自:http://www.cnblogs.com/scorpiozj/p/3302270.html 最近在sae ...
- android view : 概述
关于view的显示和绘制,不会去了解底层,仅仅在framework层做一些概述:以oo的思想,那么窗口的显示,内容的显示一定都有对应的类来相对应.了解了这一点之后,就去抽象一下android为了显示窗 ...
- Java数据结构和算法之链表
三.链表 链结点 在链表中,每个数据项都被包含在‘点“中,一个点是某个类的对象,这个类可认叫做LINK.因为一个链表中有许多类似的链结点,所以有必要用一个不同于链表的类来表达链结点.每个LINK对象中 ...
- 《JavaScript模式》第4章 函数
@by Ruth92(转载请注明出处) 第4章:函数 一.JavaScript 中函数的两个重要特征 函数是第一类对象,可以作为带有属性和方法的值以及参数进行传递: 函数提供了局部作用域,而其他大括号 ...
- IPC-管道
内容提要: 管道简介 使用无名管道实现一个简单的本地文件服务器 使用标准I/O函数库提供的管道实现 使用popen实现本地文件服务器 有名管道-FIFO 使用FIFO改写本地文件服务器 管道和FIFO ...
- C++ 文件读取
#include <iostream> #include <fstream> #include <string> using namespace std; int ...
- jq 一些小方法
js 控制a标签的onclick方法 document.getElementById("a3").onclick = ""; window.document.g ...
- ✡ leetcode 166. Fraction to Recurring Decimal 分数转换 --------- java
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- HDU 2577(DP)
题意:要求一个字符串输入,按键盘的最少次数.有Caps Lock和Shift两种转换大小写输入的方式 思路:用dpa与dpb数组分别记录Caps Lock的开关状态,dpa表示不开,dpb表示开 代码 ...