LA 3602 DNA Consensus String
最近审题老是一错再错,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的更多相关文章
- 贪心水题。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 ...
- LA 3602 DNA Consensus String (暴力枚举)
题意:给定m个长度为n的DNA序列,求一个最短的DNA序列,使得总Hamming距离最小. Hamming距离等于字符不同的位置个数. 析:看到这个题,我的第一感觉是算时间复杂度,好小,没事,完全可以 ...
- LA 3602 - DNA Consensus String 枚举
原题地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- uvalive 3602 DNA Consensus String
https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序 ...
- UVa 3602 - DNA Consensus String 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 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 ...
- uva 1368 DNA Consensus String
这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串. 我的思路就是求每一列每 ...
随机推荐
- IT架构之IT架构模型——思维导图
参考: [日] 野村综合研究所系统咨询事业本部. 图解CIO工作指南. 周自恒译 人民邮电出版社,2014
- css 内联元素inline 行框全解
首先看一篇文章: CSS框模型:一切皆为框 — 从行框说起 一 行框 看图说话 上图代表了框模型中的行框.line-height 属性设置行间的距离(行高).该属性会影响行框的布局.在应用到一个块级元 ...
- 更改cmd代码页,修正语言显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 rem 英文 chcp 437 rem 日文 chcp 932 rem 简体中文 chcp 936 re ...
- asp.net跳转页面的三种方法比较
目前,对于学习asp.net的很多朋友来讲,实现跳转页面的方法还不是很了解.本文将为朋友们介绍利用asp.net跳转页面的三种方法,并对其之间的形式进行比较,希望能够对朋友们有所帮助. ASP.NET ...
- http://blog.csdn.net/luxiaoyu_sdc/article/details/7333024
http://blog.csdn.net/luxiaoyu_sdc/article/details/7333024 http://blog.csdn.net/kkdelta/article/detai ...
- Visual Studio 2010 快捷键
Visual Studio 2010 快捷键: CTRL + SHIFT + B 生成解决方案CTRL + F7 生成编译CTRL + O 打开文件CTRL + SHIFT + O 打开项目CTRL ...
- 怎样查看Tomcat动态控制台信息
在web项目调试期间,时常需要查看输出的调试信息,例如当hibernate设置为显示SQL语句时,每次运行的SQL语句会输出到终端,另外有时需要在代码中插入一些输出语句,以方便掌握运行情况,但当插入S ...
- 关于J-LINK升级最新固件后无法连上的一点分析
昨天升级了最新的 Keil MDK 4.53,怕它老是提示 J-Link 要升级,就去 SEGGER 的网站下了个最新版的 J-Link 软件包(4.46F 版的),装好后运行 J-Link Comm ...
- Spring笔记——Spring框架简介和初次框架配置
Spring简介 Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Deve ...
- ajax:$.get()
提要: $.get("异步文件",数值,回调函数); 加载XML文档 a.xml <?xml version="1.0" encoding="U ...