Advertisement
juaniisuar

Untitled

Oct 23rd, 2018
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <cmath>
  5. #include <map>
  6. #include <iomanip>
  7.  
  8. #define pb push_back
  9. #define fst first
  10. #define snd second
  11.  
  12. #define forn(i,n) forr(i,0,n)
  13. #define forr(i,x,n) for(int i=(x); i<(n); i++)
  14.  
  15. using namespace std;
  16.  
  17. typedef unsigned long long ll;
  18.  
  19. const ll MAXN = 50005;
  20. const ll INF = 1e18;
  21. const ll MOD = 1e9 + 7;
  22.  
  23. struct pt {
  24. int x, y, id;
  25. };
  26.  
  27. inline bool cmp_x (const pt & a, const pt & b) {
  28. return a.x < b.x || a.x == b.x && a.y < b.y;
  29. }
  30.  
  31. inline bool cmp_y (const pt & a, const pt & b) {
  32. return a.y < b.y;
  33. }
  34.  
  35. pt a[MAXN];
  36.  
  37. double mindist;
  38. int ansa, ansb;
  39.  
  40. inline void upd_ans (const pt & a, const pt & b) {
  41. double dist = sqrt ((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + .0);
  42. if (dist < mindist)
  43. mindist = dist, ansa = a.id, ansb = b.id;
  44. }
  45.  
  46. void rec (int l, int r) {
  47. if (r - l <= 3) {
  48. for (int i=l; i<=r; ++i)
  49. for (int j=i+1; j<=r; ++j)
  50. upd_ans (a[i], a[j]);
  51. sort (a+l, a+r+1, &cmp_y);
  52. return;
  53. }
  54.  
  55. int m = (l + r) >> 1;
  56. int midx = a[m].x;
  57. rec (l, m), rec (m+1, r);
  58. static pt t[MAXN];
  59. merge (a+l, a+m+1, a+m+1, a+r+1, t, &cmp_y);
  60. copy (t, t+r-l+1, a+l);
  61.  
  62. int tsz = 0;
  63. for (int i=l; i<=r; ++i)
  64. if (abs (a[i].x - midx) < mindist) {
  65. for (int j=tsz-1; j>=0 && a[i].y - t[j].y < mindist; --j)
  66. upd_ans (a[i], t[j]);
  67. t[tsz++] = a[i];
  68. }
  69. }
  70.  
  71. int N;
  72.  
  73. int main(){
  74. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  75.  
  76. cin >> N;
  77. forn(i,N){
  78. cin >> a[i].x >> a[i].y;
  79. a[i].id = i;
  80. }
  81. sort(a, a+N, &cmp_x);
  82. mindist = INF;
  83. rec(0,N-1);
  84.  
  85. cout << min(ansa,ansb) << ' ' << max(ansa,ansb) << ' ' << fixed << setprecision(6) << mindist << endl;
  86.  
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement