<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
Figure 2. DNA sequences of gene X in five animals.

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>(4m50)<tex2html_verbatim_mark>represents the number of DNA sequences and n<tex2html_verbatim_mark>(4n1000)<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的更多相关文章

  1. UVA-1368 DNA Consensus String(思路)

    题目: 链接 题意: 题目虽然比较长,但读完之后题目的思路还是比较容易想出来的. 给出m个长度为n的字符串(只包含‘A’.‘T’.‘G’.‘C’),我们的任务是得出一个字符串,要求这个字符串与给出的m ...

  2. 贪心水题。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 ...

  3. DNA Consensus String

    题目(中英对照): DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It co ...

  4. 紫书第三章训练1 E - DNA Consensus String

    DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of ...

  5. UVa1368/ZOJ3132 DNA Consensus String

    #include <stdio.h>#include <string.h> int main(){    int a[4][1000]; // A/C/G/T在每列中出现的次数 ...

  6. DNA序列 (DNA Consensus String,ACM/ICPC Seoul 2006,UVa1368

    题目描述:算法竞赛入门经典习题3-7 题目思路:每列出现最多的距离即最短 #include <stdio.h> #include <string.h> int main(int ...

  7. uva 1368 DNA Consensus String

    这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串. 我的思路就是求每一列每 ...

  8. uvalive 3602 DNA Consensus String

    https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序 ...

  9. 【每日一题】UVA - 1368 DNA Consensus String 字符串+贪心+阅读题

    https://cn.vjudge.net/problem/UVA-1368 二维的hamming距离算法: For binary strings a and b the Hamming distan ...

随机推荐

  1. GO实例3 Slice append打印

    package main import "fmt" func main(){ ]int slice:=array[:] slice[]='a' slice[]='b' s1:=ap ...

  2. Java添加自定义注解

    今天在整合MyBatis过程中,我使用扫描的方式去扫描DAO目录下的Java文件,但是在Service层使用Autowired的时候报错,但是工程能正常运行,此处有Bug! 解决方案: 1.创建 an ...

  3. UIApplication详解再解-备

    每个app有且只有一个UIApplication对象,当程序启动的时候通过调用UIApplicationMain方法得到的.可以通过sharedApplication方法得到. UIApplicati ...

  4. GridView 中Item项居中显示

    直接在GridView中设置 android:gravity="center"这个属性是不起作用的.要在你adapter中的布局文件中设 置android:layout_gravi ...

  5. haskell学习笔记_函数

    一开始学习函数式编程语言就被告知函数式编程语言是一种“定义式”的语言,而不是一种命令式的语言,在学习haskell的函数语法时,此感觉更加强烈,haskell的函数定义倾向于一种类似C++里面的swi ...

  6. 在微软平台上运行 SAP 应用程序

     本博客介绍了在微软平台上运行 SAP 应用程序的相关信息,作者在基于微软平台使用 SAP 方面有着数十年经验. 发布关于 Azure 的 SAP 说明 几个月前,SAP 针对适用于 SAP 软件 ...

  7. 构建一个基于 Spring 的 RESTful Web Service

    本文详细介绍了基于Spring创建一个“hello world” RESTful web service工程的步骤. 目标 构建一个service,接收如下HTTP GET请求: http://loc ...

  8. c语言结构体数组定义的三种方式

    struct dangdang { ]; ]; ]; int num; int bugnum; ]; ]; double RMB; int dangdang;//成员名可以和类名同名 }ddd[];/ ...

  9. 第25讲 UI组件之 AlertDialog 的各种实现

    第25讲 UI组件之AlertDialog 的各种实现 对话框(Dialog)是程序运行中的弹出窗口,例如当用户要删除一个联系方式时,会弹出一个对话框. Android提供了多种对话框:警告对话框(A ...

  10. 集成Dubbo服务(Spring)

    Dubbo是什么? Dubbo是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的各成员站点. Dubbo[]是 ...