Advertisement
Josif_tepe

Untitled

Sep 30th, 2023
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <queue>
  2. #include <iostream>
  3. #include <vector>
  4. #include <cstring>
  5. #include <iostream>
  6. #include <set>
  7. #include <cstring>
  8. #include <stack>
  9. #include <algorithm>
  10. #include <map>
  11. #include <cmath>
  12. //#include <bits/stdc++.h>
  13. using namespace std;
  14. typedef long long ll;
  15. const int maxn = 3e5 + 10;
  16. const ll INF = 3e16 + 10;
  17.  
  18.  
  19. int main() {
  20.     ios_base::sync_with_stdio(false);
  21.     int n;
  22.     cin >> n;
  23.     vector<pair<int, int>> cords(n);
  24.     for(int i = 0; i < n; i++) {
  25.         cin >> cords[i].first >> cords[i].second;
  26.     }
  27.    
  28.     sort(cords.begin(), cords.end());
  29.     set<pair<int, int>> st;
  30.     st.insert(make_pair(cords[0].first, cords[0].second));
  31.     ll shortest_distance = 1e9, result = 1e9;
  32.     for(int i = 1; i < n; i++) {
  33.         set<pair<int, int>>::iterator it1 = st.lower_bound(make_pair(cords[i].first - shortest_distance, cords[i].second - shortest_distance));
  34.        
  35.         set<pair<int, int>>::iterator it2 = st.upper_bound(make_pair(cords[i].first + shortest_distance, cords[i].second + shortest_distance));
  36.        
  37.         if(it1 == st.end()) {
  38.             continue;
  39.         }
  40.         for(set<pair<int, int>>::iterator it = it1; it != it2; it++) {
  41.             ll dist = (cords[i].first - it->first) * (cords[i].first - it->first) + (cords[i].second - it->second) * (cords[i].second - it->second);
  42.             result = min(result, dist);
  43.             shortest_distance = min(shortest_distance, dist);
  44.         }
  45.         st.insert(make_pair(cords[i].first, cords[i].second));
  46.        
  47.     }
  48.     cout << sqrt(result) << endl;
  49.     return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement