![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
#include <iostream>
#include <cmath>
using namespace std;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
typedef struct node
{
int a[101][101];
int sum[101];
double avg[101];
}node;
int main()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int i,j,n,m,ans,T;
scanf("%d",&T);
while(T--)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
scanf("%d%d",&m,&n);
node mm;
ans=0;
memset(mm.sum,0,sizeof(mm.sum));
for(i=0;i<n;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(j=0;j<m;j++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
scanf("%d",&mm.a[i][j]);
mm.sum[j]+=mm.a[i][j];
}
}
for(i=0;i<m;i++)
mm.avg[i]=1.0*mm.sum[i]/n;
double min=1000000.0;
int index=0;
for(i=0;i<n;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
double temp=0.0;
for(j=0;j<m;j++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
temp+=fabs(mm.a[i][j]-mm.avg[j]);
}
if(temp<min)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
min=temp;
index=i;
}
}
for(i=0;i<n;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(i!=index)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(j=0;j<m;j++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ans+=abs(mm.a[index][j]-mm.a[i][j]);
}
}
}
printf("%d\n",ans);
}
return 0;
}