UVA 1368 DNA

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxn 1000+10
int main(){
  int m,n,t,ans[maxn*50];
  char s[60][maxn];
  scanf("%d",&t);
  while(t--){
  scanf("%d%d",&m,&n);
  for(int i=0;i<m;i++){
    scanf("%s",s[i]);
  }
   char a;
   int sum=0;
    for(int j=0;j<n;j++){
       int mini=0;
       memset(ans,0,sizeof(ans));
       for(int i=0;i<m;i++){
       ans[s[i][j]]++;
       if(ans[s[i][j]]>mini){
        mini=ans[s[i][j]];
        a=s[i][j];
        }
        if(ans[s[i][j]]==mini&&a>s[i][j]){
          mini=ans[s[i][j]];
          a=s[i][j];
        }
       }
       printf("%c",a);
       for(int i=0;i<m;i++){
        if(s[i][j]!=a) sum++;
       }
    }
    printf("\n");
    printf("%d\n",sum);
  }
  return 0;
}
时间: 2024-11-05 14:48:21

UVA 1368 DNA的相关文章

uva 1368 - DNA Consensus String(字符串处理)

uva 1368 - DNA Consensus String 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 repre

UVA - 1368 DNA Consensus String

DNA Consensus String Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description  Figure 1. DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of four different nuc

UVA 1368 DNA(模拟+贪心)

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

uva 1368 DNA Consensus String 字符串

这学期离散数学的最后一章刚学了类似的东西 什么decoding function和humming distance手算起来才有点难 编程的话就很水了 #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <cmath> #include <set> #include

DNA Consensus String,( UVa, 1368 )

题目链接 :https://vjudge.net/problem/UVA-1368 题目首先得知道什么是Hamming距离(自行查找),然后注意出现多个解是选择字典序小者(直接将字典序排号比较),**注意数组大小. 1 #include<stdio.h> 2 #include<string.h> 3 #define maxn 1000 4 #define maxm 1000 5 6 char DNA[maxn][maxm]; 7 int main() 8 { 9 int N; 10

1368.DNA Consensus String

题目要求是对几个字符串进行分析,得到一个最优的字符串,使它满足与要求的字符串不同的字符之和最小.如果有多种解,则输出字典序最小的. 注意:字符串的结束时 \0  一定要加上 1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 6 const int maxn=1005; 7 char DNA[55][maxn]; 8 struct node{ 9

UVa 1368

背景:每列找出最多重复次数即可. #include<stdio.h> #include<string.h> int main(void){ int t; scanf("%d",&t); while(t--){ int n,m; scanf("%d %d",&n,&m); char DNA[n][m+1]; for(int i=0;i<n;i++) scanf("%s",DNA[i]); int

uva 1368 水题

枚举每一列的位置,求哪个字符出现的次数最多 #include<iostream> #include<string> #include<map> #include<cstdio> #include<vector> #include<algorithm> #include<assert.h> #include<cstring> using namespace std; #define _for(i, a, b) f

UVa1368.DNA Consensus String

原题链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4114 13845357 1368 DNA Consensus String Accepted C++ 0.022 2014-07-07 12:29:30  DNA Consensus String Figure 1. DNA (Deoxyribonucleic Acid) is t