UVa1368/ZOJ3132 DNA Consensus String
#include <stdio.h>
#include <string.h>
int main()
{
int a[4][1000]; // A/C/G/T在每列中出现的次数
char c, x;
char bas[4] = { 'A', 'C', 'G', 'T' };
int T, m, n, i, j, k, dist;
scanf("%d", &T);
while (T--)
{
scanf("%d %d\n", &m, &n);
memset(a, 0, sizeof(a));
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
c = getchar();
if (c == 'A')
++a[0][j];
else if (c == 'C')
++a[1][j];
else if (c == 'G')
++a[2][j];
else
++a[3][j];
}
getchar();
}
dist = 0;
for (j = 0; j < n; ++j)
{
k = -1;
for (i = 0; i < 4; ++i)
{
if (a[i][j] > k)
{
k = a[i][j];
x = bas[i];
}
}
for (i = 0; i < 4; ++i)
{
if (bas[i] != x)
dist += a[i][j];
}
putchar(x);
}
printf("\n%d\n", dist);
}
return 0;
}
UVa1368/ZOJ3132 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 ...
- 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 ...
- DNA序列 (DNA Consensus String,ACM/ICPC Seoul 2006,UVa1368
题目描述:算法竞赛入门经典习题3-7 题目思路:每列出现最多的距离即最短 #include <stdio.h> #include <string.h> int main(int ...
- UVA-1368 DNA Consensus String(思路)
题目: 链接 题意: 题目虽然比较长,但读完之后题目的思路还是比较容易想出来的. 给出m个长度为n的字符串(只包含‘A’.‘T’.‘G’.‘C’),我们的任务是得出一个字符串,要求这个字符串与给出的m ...
- uva 1368 DNA Consensus String
这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串. 我的思路就是求每一列每 ...
- uvalive 3602 DNA Consensus String
https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序 ...
- 【每日一题】UVA - 1368 DNA Consensus String 字符串+贪心+阅读题
https://cn.vjudge.net/problem/UVA-1368 二维的hamming距离算法: For binary strings a and b the Hamming distan ...
随机推荐
- C语言入门(9)——局部变量与全局变量
变量有效性的范围称变量的作用域.C语言中所有的量都有自己的作用域.变量说明的方式不同,其作用域也不同. C语言中的变量,按作用域范围可分为两种,即局部变量和全局变量. 局部变量 局部变量也称为内部 ...
- Xcode 真机测试破解方法(转加修改)xcode 4.3 通过
Xcode 真机测试破解方法(转加修改)xcode 4.3 通过 生成本机证书 应用程序->实用工具->钥匙串访问 菜单:钥匙串访问->证书助理->创建证书, 然后按以下图片顺 ...
- C,C++经典(程序、错误程序)
1,程序 未执行完错误的return 0
- DataGuard failover dg role自动切换模式测试
1,在脚本中代入create db flash backup point for recover dg 2,测试前主备库状态(备库现角色验证,主库监听状态-->有意stop) 主要验证思路, 脚 ...
- Swift学习之十四:闭包(Closures)
* 闭包(Closures) * 闭包是自包含的功能代码块,可以在代码中使用或者用来作为参数传值. * 在Swift中的闭包与C.OC中的blocks和其它编程语言(如Python)中的lambdas ...
- JavaScript奇技淫巧45招
JavaScript奇技淫巧45招 撰写于 2015年1月5日 修改于 2016年6月16日 分类 翻译 标签 JavaScript 本文是一篇翻译文章,原文信息如下: 原文:45 Useful Ja ...
- C#后台创建控件并获取值
前台代码 <form id="form1" runat="server"> <div> <div class="item ...
- 在win7下装ubuntu(硬盘版安装)及遇到的问题
都怪自己弄什么Ubuntu下的Android Studio,因为GFW,gradle总下载不了,用命令行下载一半关机了,然后Ubuntu就这样被我搞残废了.又张罗着重装. 其实就是参照网上的帖子,算是 ...
- MATLAB中digits和vpa
digits: DIGITS Set variable precision digits. Digits determines the accuracy of variable precision n ...
- 用例图(UseCase Diagram)—UML图(一)
从上面的用例图模型,我们可以大致了解用例图所描述的是什么.下面进行详细介绍. 用例图,即用来描述什么角色通过某某系统能做什么事情的图,用例图关注的是系统的外在表现,系统与人的交互,系统与其它系统的 ...