Title Description
A point every time unit diffuses a distance in the four directions, as shown in FIG.
Two points a, b communication, referred to as E (a, b), if and only if the diffusion regions a, b are common. Definition of communication block is arbitrary two points within the block u, v path will exist without fail e (u, a0), e (a0, a1), ..., e (ak, v). To n to a point on a given plane, and asked what is the earliest time that they form a communication block.
Input and output formats
Input formats:
The first line of a number n, the n lines, each line point coordinates.
[Data] scale
For 20% of the data, to meet 1≤N≤5; 1≤X [i], Y [i] ≤50;
To 100% of the data satisfies 1≤N≤50; 1≤X [i], Y [i] ≤10 ^ 9.
Output formats:
A number representing the earliest time point of all the communication block is formed.
Sample input and output
2 0 0 5 5
5
bipartite and answers Manhattan distance <= mid * 2
#include<iostream> #include<cstdio> #include<cmath> using namespace std; int xs[51]; int ys[51];//坐标 int ints[51];//并查集 int find(int n){ if(ints[n]==n)return(n); return(ints[n]=find(ints[n])); } int main(){ int n; cin>>n; for(int i=0;i<n;i++)cin>>xs[i]>>ys[i]; int l=0,r=1000000000; int ans=0;//最终答案 while(l<=r){ int mid=(l+r)>>1;//二分答案 for(register int i=0;i<n;i++){ ints[i]=i; }//初始化并查集 for(register int i=0;i<n;i++){ for(register intJ = I + . 1 ; J <n-; J ++ ) { int DIS = ABS (XS [I] -xs [J]) + ABS (YS [I] - YS [J]); IF (DIS <= MID * 2 ) { // can spread to the sides and even int AA = Find (I), = ab & Find (J); IF (AA = ab &!) INTS [AA] = ab &; } } } int CNT = 0 ; // communication block number for (Register int I = 0 ; I <n-; I ++ ) { IF (INTS [I] == I) CNT ++ ; } IF (CNT ==. 1 ) { ANS = MID; R & lt = mid- . 1 ; } // Only one block is updated communication answer look down the else { L = MID + . 1 ; } } COUT << ANS << endl; return ( 0 ); }