原题地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1603

题目大意:

给定m个长度均为n的DNA序列,使其(那个啥序列来着,噢)Hamming,(好吧,这单词我复制的T T)序列尽量短,Hamming指的是字符不同位置的个数。(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. `AGCAT和GGAAT 的Hamming为2,因为第一和第三字母不一样)如果有多解,取字典序小的。

数据量小,可以直接枚举。.然后就没有然后了。@。@

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=1000+10;
char a[50+10][MAXN],ans[MAXN];
int A,C,G,T,diff;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
diff=0;
int n,m;
scanf("%d%d",&m,&n);
for(int i=0;i<m;i++)
scanf("%s",a[i]);
for(int i=0;i<n;i++)
{
A=G=C=T=0;
for(int j=0;j<m;j++)
{
switch(a[j][i])
{
case 'A':A++;break;
case 'C':C++;break;
case 'G':G++;break;
case 'T':T++;break;
}
}
int MAX=0;
MAX=max( max (max (max(MAX,A) ,C) ,G) ,T); if(MAX==A) { diff=diff+C+G+T; ans[i]='A'; }
else if(MAX==C) { diff=diff+A+G+T; ans[i]='C'; }
else if(MAX==G) { diff=diff+C+A+T; ans[i]='G'; }
else if(MAX==T) { diff=diff+C+G+A; ans[i]='T'; }
}
ans[n]='\0'; //注意末尾填结束符,除非你逐个字符输出
printf("%s\n%d\n",ans,diff);
}
}
05-22 17:06