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序列的汉明距离最短,若有多个解则输出字典序 ...
随机推荐
- hive的基本操作
1.创建表 First, create a table with tab-delimited text file format: (1)CREATE TABLE u_data ( userid INT ...
- windows核心编程---第一章 谈谈windows中的错误处理机制
我们写的函数会用返回值表示程序执行的正确与否,使用void,就意味着程序一定不会出错.Bool类型标识true时为真,false时为假.其他类型根据需要可以定义成不同意义. Win ...
- sql基本增删改查语法
sql语法学习(适合新手) 1.插入数据 语法格式: INSERT [INTO] <表名> [列名] VALUES <值列表> insert into students(sna ...
- 拔靴法--Bootstrap--R语言实现
拔靴法属于重复抽样(resampling)方法,与Monte Carlo相比,二者真实的母体不同.它是将已有的观察值作为母体重复抽样, 以求取原先资料不足二无法探讨的资料特性. 举个例子,假设x1,x ...
- YII2.0 验证表单
控制器代码 <?php namespace app\modules\pub\controllers; use Yii; use backend\base\BaseController; use ...
- Boundaries
Using Third-Party Code There is a natural tension between the provider of an interface and the user ...
- 打包ane之后在FB上生成ipa的阶段错误
1. 初次打包 碰到这个错误得 就是你mac 上jre版本的问题 此时用 FB 必须是跑在jre1.6版本上的 我得是1.8 上图 版本可以自己查下 已经截图了 而且 你如果想要下载 1.6版本的 就 ...
- 从零开始学习Node.js例子六 EventEmitter发送和接收事件
pulser.js /* EventEmitter发送和接收事件 HTTPServer和HTTPClient类,它们都继承自EventEmitter EventEmitter被定义在Node的事件(e ...
- Array.prototype.indexOf
arr.indexOf(searchElement[, fromIndex = 0]) Array.prototype.indexOf()
- 计算std:string的字节长度
如果项目本身是使用 Unicode 字符集和utf8编码,std::string的length(),size()甚至是c的strLen取到的都是字节长度了,比如三个汉字,就是9, 以上情况不满足的话, ...