您的位置:首页 > 其它

UVa 1368 DNA Consensus String

2015-09-06 14:44 405 查看
题意:给出n个长度为len的DNA序列,求一个DNA序列,使得该序列到这m个DNA序列的距离尽量短

两个等长字符串的字符不同的位置个数即为两个字符串之间的距离

思路:记录下每个位置出现次数最多的字母,再扫一遍这n个串,求出距离

// Created by Chenhongwei in 2015.
// Copyright (c) 2015 Chenhongwei. All rights reserved.

#include "iostream"
#include "cstdio"
#include "cstdlib"
#include "cstring"
#include "climits"
#include "queue"
#include "cmath"
#include "map"
#include "set"
#include "stack"
#include "vector"
#include "sstream"
#include "algorithm"
using namespace std;
const int inf=1e8;
const int maxn=1e5;
typedef long long ll;
char s[60][1100];
int main()
{
//ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
char str[1100];
int T;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d%d\n",&n,&m);
for(int i=1;i<=n;i++)
gets(s[i]+1);
int sum=0;
for(int j=1;j<=m;j++)
{
int tmp=0;
char ans;
map<char,int> mp;
for(int i=1;i<=n;i++)
{
mp[s[i][j]]++;
if(mp[s[i][j]]>tmp||(mp[s[i][j]]==tmp&&s[i][j]<ans))
{
tmp=mp[s[i][j]];
ans=s[i][j];
}
}
sum+=n-tmp;
printf("%c",ans);
}
printf("\n%d\n",sum);
}
return 0;
}

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