[codeforces 1271C] Shawarma Tent 模拟(曼哈顿距离)
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址http://codeforces.com/contest/1271/problem/C
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
C - Shawarma Tent | GNU C++11 | Accepted | 78 ms | 0 KB |
下面代码对应的
Examples
Input
4 3 2
1 3
4 2
5 1
4 1
Output
3
4 2
Input
3 100 100
0 0
0 0
100 200
Output
2
100 0
Input
7 10 12
5 6
20 23
15 4
16 5
4 54
12 1
4 15
Output
4
10 6
#include <stdio.h>
#define INF 1000000100
int n,sx,sy,x,y;
int up=0,down=0,left=0,right=0;
int xright=INF,xleft=-1,yup=INF,ydown=-1;
int sumx,xpos,sumy,ypos;
int min(int a,int b){
return a<b?a:b;
}
int max(int a,int b){
return a>b?a:b;
}
int main(){
int i;
scanf("%d%d%d",&n,&sx,&sy);
for(i=1;i<=n;i++){
scanf("%d%d",&x,&y);
if(x>sx)right++,xright=min(xright,x);
else if(x<sx)left++,xleft=max(xleft,x);
if(y>sy)up++,yup=min(yup,y);
else if(y<sy)down++,ydown=max(ydown,y);
}
if(right>left)sumx=right,xpos=xright;
else sumx=left,xpos=xleft;
if(up>down)sumy=up,ypos=yup;
else sumy=down,ypos=ydown;
if(sumx>sumy)printf("%d\n%d %d\n",sumx,xpos,sy);
else printf("%d\n%d %d\n",sumy,sx,ypos);
return 0;
}