# gavanwanggw

## 代码:

#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 10010
#define INF 0x3f3f3f3f
#define pa pair<int,int>
using namespace std;
int n;
int a[N];
int b[N];
int xx[5]={0,-1,1,0,0};
int yy[5]={0,0,0,1,-1};
struct node
{
int x,y;
}c[N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&a[i],&b[i]);
c[i].x=a[i],c[i].y=b[i];
}
sort(a+1,a+n+1),sort(b+1,b+n+1);
if(n&1)
{
int tmp=n/2+1;
int tmpx=a[tmp],tmpy=b[tmp];
int ans=0;
int flag=1;
for(int i=1;i<=n;i++)
{
if(tmpx==c[i].x&&tmpy==c[i].y){flag=0;break;}
}
if(flag)
{
for(int i=1;i<=n;i++)
{
ans+=abs(tmpx-a[i])+abs(tmpy-b[i]);
}
printf("%d 1\n",ans);
}else
{
ans=INF;
int cnt=0;
for(int i=1;i<=4;i++)
{
int x=tmpx+xx[i],y=tmpy+yy[i];
int ret=0;
for(int j=1;j<=n;j++)
{
ret+=abs(x-c[j].x)+abs(y-c[j].y);
}
if(ret<ans)ans=ret,cnt=1;
else if(ret==ans)cnt++;
}
printf("%d %d\n",ans,cnt);
}
}else
{
int tmpx1=a[n/2],tmpx2=a[n/2+1];
int tmpy1=b[n/2],tmpy2=b[n/2+1];
int ret=0,cnt=(tmpx2-tmpx1+1)*(tmpy2-tmpy1+1);
for(int k=1;k<=n;k++)
{
if(c[k].x>=tmpx1&&c[k].x<=tmpx2&&c[k].y>=tmpy1&&c[k].y<=tmpy2)cnt--;
ret+=abs(tmpx1-c[k].x)+abs(tmpy1-c[k].y);
}
printf("%d %d\n",ret,cnt);
}
} 

posted on 2017-06-09 21:58  gavanwanggw  阅读(179)  评论(0编辑  收藏  举报