The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes.html
The main school of the capital is located in . There are n students attending this school, the i-th of them lives in the house located in (xi,yi). It is possible that some students live in the same house, but no student lives in .web
After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the -th student goes from the school to his house is .api
The Provision Department of Berland has decided to open a shawarma tent somewhere in the capital (at some point with integer coordinates). It is considered that the
-th student will buy a shawarma if at least one of the shortest paths from the school to the
-th student’s house goes through the point where the shawarma tent is located. It is forbidden to place the shawarma tent at the point where the school is located, but the coordinates of the shawarma tent may coincide with the coordinates of the house of some student (or even multiple students).數組
You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself.app
The first line contains three integers , , — the number of students and the coordinates of the school, respectively.less
Then lines follow. The -th of them contains two integers — the location of the house where the -th student lives. Some locations of houses may coincide, but no student lives in the same location where the school is situated.ide
The output should consist of two lines. The first of them should contain one integer — the maximum number of students that will buy shawarmas at the tent.svg
The second line should contain two integers and — the coordinates where the tent should be located. If there are multiple answers, print any of them. Note that each of and should be not less than and not greater than .ui
給定原點和若干點,定義點到原點距離爲 ,如今要選擇一個位置建造賬篷,若一個點到原點有通過這個賬篷的最短路徑,那麼就會產生 點貢獻。問在哪裏建造賬篷能得到的貢獻值最大。this
很顯然,一個點到原點的最短路徑可行方案覆蓋了以該點和原點爲對角頂點的整個矩形。
大概就是這樣的一個矩形。所以我有了一個很天然的思路:每次給這個矩形裏全部值+1,最後統計答案遍歷每一個點便可。
打算二維樹狀數組搞一搞,而後發現值域過大……
正解:這個矩形的某一個頂點是肯定的,即原點是肯定的,那麼必定只有這幾種狀況:
原點左邊的全部點都會對建築在原點左一格的狀況產生貢獻。
原點右邊的全部點都會對建築在原點右一格的狀況產生貢獻。
原點上方的全部點都會對建築在原點上一格的狀況產生貢獻。
原點下方的全部點都會對建築在原點上一格的狀況產生貢獻。
在其餘位置建築的話,確定都不如這四個點,能夠畫一下貢獻區域感覺一下。
#include <cstdio> using namespace std; inline char nc() { static char buf[1000000],*p1 = buf,*p2 = buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++; } template<typename T> void read(T &r) { static char c; r=0; for(c=nc();c>'9'||c<'0';c=nc()); for(;c>='0'&&c<='9';r=(r<<1)+(r<<3)+(c^48),c=nc()); } int n,p,q; int l,r,top,bottom; inline int max(const int &a,const int &b){return a>b?a:b;} int main() { read(n); read(p); read(q); int x,y; for(;n;--n) { read(x); read(y); if(x < p) ++l; else if(x > p) ++r; if(y > q) ++top; else if(y < q) ++bottom; } int maxx = max(l,max(r,max(top,bottom))); printf("%d\n",maxx); if(maxx == l) printf("%d %d",p - 1,q); else if(maxx == r) printf("%d %d",p + 1,q); else if(maxx == top) printf("%d %d",p,q+1); else printf("%d %d",p,q-1); return 0; }