您的位置:首页 > 其它

DNA Consensus String

2015-10-16 10:05 253 查看
UVa1368

这道题我以为是要求一个串到所有串的距离最小,不过好像可以扩展,但是我好像写不出。

#include <stdio.h>
#include <string.h>
const int maxn = 1005;
char str[maxn][maxn], ch[5] = "ACGT", ans[maxn];
int cnt[5];
int main ( )
{
int T, n, m, value;
scanf ( "%d", &T );
while ( T -- )
{
value = 0;
scanf ( "%d%d", &n, &m );
for ( int i = 0; i < n; i ++ )
scanf ( "%s", str[i] );
for ( int j = 0; j < m; j ++ )
{
memset ( cnt, 0, sizeof ( cnt ) );
for ( int i = 0; i < n; i ++ )
{
for ( int k = 0; k < 4; k ++ )
if ( str[i][j] == ch[k] )
cnt[k] ++;
}
int mx = 0, mi = 0;
for ( int i = 0; i < 4; i ++ )
if ( mx < cnt[i] )  //ch存放字典序
{
mx = cnt[i];
mi = i;
}
value = value+n-mx;
ans[j] = ch[mi];
}
ans[m] = '\0';
printf ( "%s\n%d\n", ans, value );
}
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: