题意:给定n个字符串,求最小距离的串。
/* ***********************************************
Author :Lu_cky
Created Time :2016-6-15 8:43:17
File Name :xiao.cpp
************************************************ */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define LL long long
using namespace std;
const int SIZE=1e6+10;
const int maxn=1<<30;
char cmap[55][1010];
int n,m;
int solve(int x){
map<char,int>mp;
for(int i=0;i<n;i++){
char ch=cmap[i][x];
if(mp.find(ch)==mp.end())mp[ch]=1;
else mp[ch]++;
}
map<char,int>::iterator it,ans;
int Max=-maxn;
for(it=mp.begin();it!=mp.end();it++){
if((*it).second>Max){
ans=it;
Max=(*it).second;
}
}
printf("%c",(*ans).first);
return n-Max;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
scanf("%d",&T);
for(int cas=1;cas<=T;cas++){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%s",cmap[i]);
int ans=0;
for(int i=0;i<m;i++)
ans+=solve(i);
printf("\n%d\n",ans);
}
return 0;
}