Advertisement
yuawn

algo_report1

Oct 16th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<algorithm>
  4. #define MAX 1000
  5.  
  6. bool cx( point a , point b ) { return a.x < b.x };
  7. bool cy( point a , point b ) { return a.y < b.y };
  8.  
  9. struct point{
  10.     double x , y;
  11. }map[MAX] , mapy[MAX];
  12.  
  13.  
  14. double solve( int L , int R ){
  15.     if( L >= R ) return 1e7;
  16.  
  17.     int mid = ( L + R ) >> 1 , t = 0;
  18.  
  19.     double d = min( solve( L , M ) , solve( M + 1 , R ) );
  20.  
  21.     for( int i = mid ; i >= L && map[mid].x - map[i].x < d; --i ) mapy[t++] = map[i];
  22.     for( int i = M + 1 ; i <= R && map[i].x - map[mid].x < d ; ++i ) mapy[t++] = map[i];
  23.  
  24.     sort( mapy , mapy + t , cy );
  25.  
  26.     for( int i = 0 ; i < t - 1 ; i++ )
  27.         for( int j = 1 ; j < 3 && i + j < t ; j++ )
  28.             d = abs( mapy[i] - mapy[i + j] ) < d ? abs( mapy[i] - mapy[i + j] ) : d;
  29.  
  30.     return d;
  31. }
  32.  
  33.  
  34. void init(){
  35.     // create map
  36. }
  37.  
  38. int main(){
  39.     init();
  40.     sort( map , map + MAX , cx );
  41.     solve();
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement