uva1368 DNA Consensus String
<tex2html_verbatim_mark> Figure 1.DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of four different nucleotides, namely Adenine, Thymine, Guanine, and Cytosine as shown in Figure 1. If we represent a nucleotide by its initial character, a DNA strand can be regarded as a long string (sequence of characters) consisting of the four characters A, T, G, and C. For example, assume we are given some part of a DNA strand which is composed of the following sequence of nucleotides:
``Thymine-Adenine-Adenine-Cytosine-Thymine-Guanine-Cytosine-Cytosine-Guanine-Adenine-Thymine"
Then we can represent the above DNA strand with the string ``TAACTGCCGAT." The biologist Prof. Ahn found that a gene X commonly exists in the DNA strands of five different kinds of animals, namely dogs, cats, horses, cows, and monkeys. He also discovered that the DNA sequences of the gene X from each animal were very alike. See Figure 2.
| DNA sequence of gene X | |
| Cat: | GCATATGGCTGTGCA |
| Dog: | GCAAATGGCTGTGCA |
| Horse: | GCTAATGGGTGTCCA |
| Cow: | GCAAATGGCTGTGCA |
| Monkey: | GCAAATCGGTGAGCA |
Prof. Ahn thought that humans might also have the gene X and decided to search for the DNA sequence of X in human DNA. However, before searching, he should define a representative DNA sequence of gene X because its sequences are not exactly the same in the DNA of the five animals. He decided to use the Hamming distance to define the representative sequence. The Hamming distance is the number of different characters at each position from two strings of equal length. For example, assume we are given the two strings ``AGCAT" and ``GGAAT." The Hamming distance of these two strings is 2 because the 1st and the 3rd characters of the two strings are different. Using the Hamming distance, we can define a representative string for a set of multiple strings of equal length. Given a set of strings S = s1,...,sm<tex2html_verbatim_mark> of length n<tex2html_verbatim_mark> , the consensus error between a string y<tex2html_verbatim_mark> of length n<tex2html_verbatim_mark> and the set S<tex2html_verbatim_mark> is the sum of the Hamming distances between y<tex2html_verbatim_mark> and eachsi<tex2html_verbatim_mark> in S<tex2html_verbatim_mark> . If the consensus error between y<tex2html_verbatim_mark> and S<tex2html_verbatim_mark> is the minimum among all possible strings y<tex2html_verbatim_mark> of length n<tex2html_verbatim_mark> , y<tex2html_verbatim_mark> is called a consensus string ofS<tex2html_verbatim_mark> . For example, given the three strings `` AGCAT" `` AGACT" and `` GGAAT" the consensus string of the given strings is `` AGAAT" because the sum of the Hamming distances between `` AGAAT" and the three strings is 3 which is minimal. (In this case, the consensus string is unique, but in general, there can be more than one consensus string.) We use the consensus string as a representative of the DNA sequence. For the example of Figure 2 above, a consensus string of gene X is `` GCAAATGGCTGTGCA" and the consensus error is 7.
Input
Your program is to read from standard input. The input consists of T<tex2html_verbatim_mark> test cases. The number of test cases T<tex2html_verbatim_mark> is given in the first line of the input. Each test case starts with a line containing two integers m<tex2html_verbatim_mark> and n<tex2html_verbatim_mark> which are separated by a single space. The integer m<tex2html_verbatim_mark>(4
m
50)<tex2html_verbatim_mark>represents the number of DNA sequences and n<tex2html_verbatim_mark>(4
n
1000)<tex2html_verbatim_mark> represents the length of the DNA sequences, respectively. In each of the next m<tex2html_verbatim_mark> lines, each DNA sequence is given.
Output
Your program is to write to standard output. Print the consensus string in the first line of each case and the consensus error in the second line of each case. If there exists more than one consensus string, print the lexicographically smallest consensus string. The following shows sample input and output for three test cases.
Sample Input
3
5 8
TATGATAC
TAAGCTAC
AAAGATCC
TGAGATAC
TAAGATGT
4 10
ACGTACGTAC
CCGTACGTAG
GCGTACGTAT
TCGTACGTAA
6 10
ATGTTACCAT
AAGTTACGAT
AACAAAGCAA
AAGTTACCTT
AAGTTACCAA
TACTTACCAA
Sample Output
TAAGATAC
7
ACGTACGTAA
6
AAGTTACCAA
12
这个问题比较简单,注意字典序就好了。
附上AC代码:
#include<iostream>
#include<algorithm> using namespace std;
char str[][];
char ch[];
int t[];
int n;
int a,b;
int Sum;
int Flag;
int main()
{
cin >> n;
while(n--)
{
Sum=;
cin >> a >> b;
for(int i=;i<a;i++)
cin >> str[i];
for(int i=;i<b;i++)
{
Flag=;
t[]=t[]=t[]=t[]=;
for(int j=;j<a;j++)
{
if(str[j][i]=='A') t[]++;
if(str[j][i]=='C') t[]++;
if(str[j][i]=='G') t[]++;
if(str[j][i]=='T') t[]++;
}
for(int i=;i<;i++)
if(t[i]>t[Flag]) Flag=i;
if(Flag==) cout << 'A';
if(Flag==) cout << 'C';
if(Flag==) cout << 'G';
if(Flag==) cout << 'T';
Sum+=t[Flag];
}
cout << endl;
cout << a*b-Sum << endl;
}
return ;
}
uva1368 DNA Consensus String的更多相关文章
- UVA-1368 DNA Consensus String(思路)
题目: 链接 题意: 题目虽然比较长,但读完之后题目的思路还是比较容易想出来的. 给出m个长度为n的字符串(只包含‘A’.‘T’.‘G’.‘C’),我们的任务是得出一个字符串,要求这个字符串与给出的m ...
- 贪心水题。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 ...
- 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 ...
- UVa1368/ZOJ3132 DNA Consensus String
#include <stdio.h>#include <string.h> int main(){ int a[4][1000]; // A/C/G/T在每列中出现的次数 ...
- 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
这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串. 我的思路就是求每一列每 ...
- 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 语言简历一个文件夹 并自己输入字符 来取文件夹名字
int main(void) { FILE *fp; char ch,filename[10]; scanf("%s",filename); if((fp=fopen(filena ...
- MySQL锁等待分析【1】
场景: 昨天业务系统上遇到了数据库慢的问题(对dcsdba.og_file_audit表的insert 慢&超时).分析后定位到是由于锁等待造成的.分析过程如下: 1.执行show proce ...
- [原创]零基础R语言教程---第一课---认识R语言
教程的录制的确是折腾了一番,一连录了二十多遍,有时候激动的说错了字,有时候不知道下一句说啥.. 不过好在第一课已经搞定了,哈哈. 虽然内容现在看起来还有点简单, 不过牛b也是一个过程嘛. 我会坚持下去 ...
- POJ 3525 Most Distant Point from the Sea
http://poj.org/problem?id=3525 给出一个凸包,要求凸包内距离所有边的长度的最小值最大的是哪个 思路:二分答案,然后把凸包上的边移动这个距离,做半平面交看是否有解. #in ...
- 中国IC业“芯”结:IC小国真能赶追韩美日么?
集成电路是关系到国民经济和社会发展的战略性.基础性和先导性产业,是培育发展战略性新兴产业.推动信息化和工业化深度融合的核心与基础.因此,我 国历来就十分重视集成电路产业的培育和发展,在这方面投入了大量 ...
- 树莓派入门教程——使用Qt开发界面程序
前言 Qt是一个1991年由奇趣科技开发的跨平台C++图形用户界面应用程序开发框架.它既可以开发GUI程序,也可用于开发非GUI程序,比如控制台工具和服务器.Qt是面向对象的框架,使用特 ...
- ActiveX,ATL和COM技术
首先COM的诞生本来就是基于二进制的复用思想,一直影响到了DLL的技术基础.它是一种windows下二进制模块组件与组件之间通信的规范,ActiveX就需要依赖这个技术,因为浏览器的东西可能需要获取客 ...
- WustOJ 1575 Gingers and Mints(快速幂 + dfs )
1575: Gingers and Mints Time Limit: 1 Sec Memory Limit: 128 MB 64bit IO Format: %lldSubmitted: 24 ...
- 3D objects key rendering steps
Key steps of Rendering objects: 1 Create objects’ meshes, which we can use C++’s vector container to ...
- JAVA中运用数组的四种排序方法
JAVA中在运用数组进行排序功能时,一般有四种方法:快速排序法.冒泡法.选择排序法.插入排序法. 快速排序法主要是运用了Arrays中的一个方法Arrays.sort()实现. 冒泡法是运用遍历数组进 ...