#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. 在非gui线程使用QMessageBox

    最近我写项目的时候遇到一个奇怪的需求,要在工作线程内,根据某个情况弹出一个MessageBox 但是Qt提供的MessageBox只可以在gui线程(主线程)使用,于是我就对QMessageBox封装 ...

  2. poj2578---三个数中找出第一个大于168的

    #include <stdio.h> #include <stdlib.h> int main() { int a,b,c; scanf("%d %d %d" ...

  3. 前端开发工具—fiddle

  4. mysql关联更新

    update tb_sdd_info a,tb_bnm_evian_info b set a.username=b.username where a.username=b.memberno and  ...

  5. Pro Android学习笔记(十一):了解Intent(中)

    Intent的构成 Intent能够带有action,data(由URI表达),extra data(key/value map,键值对),指定的类名(成为component name).一个inte ...

  6. Bootstrap学习之一起步

    说起Bootstrap,第一次接触到这个名词的时候还是同事在做自适应页面技术分享会时了解到,在之后的项目中就逐渐应用了这个前端WEB CSS框架.      

  7. git 使用随笔

    /*将远端库git@github.com:myrepo/base.git从远端clone到本地*/git clone git@github.com:myrepo/base.git /*克隆版本库的时候 ...

  8. ASP.NET MVC 必备知识点杂谈

    一  工程结构4个程序集 Microsoft.Web.Mvc --一些可以使用的,不确定的程序包System.Web.Mvc  --主程序库下面两个列入3.5的Net框架了System.Web.Abs ...

  9. 转 --maven系列之一 简介

    http://blog.csdn.net/jiuqiyuliang/article/details/41076215 [项目管理和构建]——Maven简介(一) 2015-01-31 21:27 68 ...

  10. 列求key出现的频率

    1 cat mc.log | grep LOGIN_GET | awk '{print $9}' | sort | uniq -c