Question: recent point (big data ).
Analysis: Divide and conquer law. First, sort all vertices by the coordinate. Then, use the sub-governance method to solve the problem.
1. Convert the problem into two subintervals of the same size for separate solutions;
2. The median is center, and the current minimum distance is the Radius Range;
3. Return the minimum value of the last two conditions.
Note: This is the first time we have made such a classic question today.
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;typedef struct nodep{double x,y;}point; point P[10004];bool cmp( point a, point b ){return a.x < b.x;}double dist( point a, point b ){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}double mindist( int a, int b ){if ( a > b ) return 40004;int l = (a+b)/2,r = (a+b)/2,mid = (a+b)/2;double d = min( mindist( a, mid-1 ), mindist( mid+1, b ) );while ( l >= a && d > P[mid].x-P[l].x ) l --;while ( r <= b && d > P[r].x-P[mid].x ) r ++;for ( int i = l+1 ; i < r ; ++ i )for ( int j = i+1 ; j < r ; ++ j ) d = min(d,dist(P[i],P[j]));return d;}int main(){int n;while ( ~scanf("%d",&n) && n ) {for ( int i = 0 ; i < n ; ++ i )scanf("%lf%lf",&P[i].x,&P[i].y);sort( P, P+n, cmp );double d = mindist( 0, n-1 );if ( d >= 10000 )printf("INFINITY\n");else printf("%.4lf\n",d);}return 0;}