#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的更多相关文章

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

  2. uva1368 DNA Consensus String

    <tex2html_verbatim_mark> Figure 1. DNA (Deoxyribonucleic Acid) is the molecule which contains ...

  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. DNA序列 (DNA Consensus String,ACM/ICPC Seoul 2006,UVa1368

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

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

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

  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. 获取EIP(汇编语言直接给Delphi变量赋值)

    var EIP: Cardinal; procedure GetEIP(); stdcall; asm pop eax; mov EIP,eax; push eax; end; procedure T ...

  2. iOS6和iOS7代码的适配(3)——坐标适配

    由于iOS7里面status bar和视图是重叠在一起了,所以应用的y坐标就没法和以前一致了,需要重新计算设定.基本上,你的应用用Xcode5运行一下就能看见这个问题,这里写了一个最简单的例子,一个V ...

  3. linux下修改.bash_profile立即生效的三种方法

    1 . .bash_profile 2 source .bash_profile 3 exec bash --login

  4. 剑指offer26 复杂链表的复制

    /* struct RandomListNode { int label; struct RandomListNode *next, *random; RandomListNode(int x) : ...

  5. 2013年 ACM 有为杯 Problem I (DAG)

    有为杯  Problem I DAG  有向无环图 A direct acylic graph(DAG),is a directed graph with no directed cycles . T ...

  6. c++ 回调类成员函数实现

    实现类成员函数的回调,并非静态函数:区分之 #ifndef __CALLBACK_PROXY_H_ #define __CALLBACK_PROXY_H_ template <typename ...

  7. LDAP验证用户名和密码

    测试环境:VS2008, NET Framework 3.5 公司打算改用LDAP来存储用户名和密码,现在用C#测试下如何能拿到LDAP中的用户名,并检测用户密码是否正确.即输入用户名和密码,可以检验 ...

  8. iOS开发篇-AFNetworking 上传和下载

    最近用到了关于AFNetworking的上传和下载问题,顺便写到博客中,以供大家参考和研究. //下载NSURLSessionConfiguration *configuration = [NSURL ...

  9. 共享bean

    到此为止,对于jsp:useBean创建的对象,我们都将它们看作是_jspService方法中的局部变量来处理(jspService由页面生成的servlet的service方法调用).虽然bean的 ...

  10. MQ学习(二)----ActiveMQ简介(转)

    1.  什么是ActiveMQ ActiveMQ是一种开源的,实现了JMS1.1规范的,面向消息(MOM)的中间件,为应用程序提供高效的.可扩展的.稳定的和安全的企业级消息通信.ActiveMQ使用A ...