danielvitor23

Gopher II

Aug 3rd, 2023
1,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4.  
  5. using namespace std;
  6. using ftype = long double;
  7.  
  8. const ftype eps = 1e-9;
  9.  
  10. int n, k;
  11.  
  12. vector<vector<int>> gr;
  13. vector<int> mt;
  14. vector<bool> used;
  15.  
  16. bool try_kuhn(int v) {
  17.     if (used[v]) return false;
  18.     used[v] = true;
  19.     for (int to : gr[v]) {
  20.         if (mt[to] == -1 or try_kuhn(mt[to])) {
  21.             mt[to] = v;
  22.             return true;
  23.         }
  24.     }
  25.     return false;
  26. }
  27.  
  28. ftype getDistance(ftype a, ftype b, ftype c, ftype d) {
  29.   return sqrtl((a - c) * (a - c) + (b - d) * (b - d));
  30. }
  31.  
  32. int main() {
  33.  
  34.   int s, v;
  35.   while (cin >> n >> k >> s >> v and n) {
  36.     vector<pair<ftype, ftype>> coord, coordHoles;
  37.  
  38.     gr.assign(n + k, vector<int>());
  39.     used.assign(n + k, false);
  40.  
  41.     for (int i = 0; i < n; ++i) {
  42.       ftype a, b; cin >> a >> b;
  43.       coord.push_back({a, b});
  44.     }
  45.  
  46.     for (int i = 0; i < k; ++i) {
  47.       ftype a, b; cin >> a >> b;
  48.       coordHoles.push_back({a, b});
  49.     }
  50.  
  51.     for (int i = 0; i < n; ++i) {
  52.       for (int j = 0; j < k; ++j) {
  53.         ftype distance = getDistance(coord[i].fi, coord[i].se, coordHoles[j].fi, coordHoles[j].se);
  54.         if (distance <= (ftype)s * v+eps) {
  55.           gr[i].push_back(n + j);
  56.           gr[n + j].push_back(i);
  57.         }
  58.       }
  59.     }
  60.  
  61.     mt.assign(n + k, -1);
  62.     vector<bool> used1(n, false);
  63.  
  64.     for (int v = 0; v < n; ++v) {
  65.       for (int to : gr[v]) {
  66.         if (mt[to] == -1) {
  67.           mt[to] = v;
  68.           used1[v] = true;
  69.           break;
  70.         }
  71.       }
  72.     }
  73.  
  74.     int cnt = 0;
  75.     for (int v = 0; v < n + k; ++v) {
  76.       if (used1[v]) continue;
  77.       used.assign(n + k, false);
  78.       int r = try_kuhn(v);
  79.       // cout << r << '\n';
  80.       cnt += r;
  81.     }
  82.  
  83.     // for (int i = 0; i < n + k; ++i)
  84.     //   if (mt[i] != -1)
  85.     //     cout << mt[i] << ' ' << i << '\n';
  86.  
  87.     // cout << cnt << '\n';
  88.     cout << max(0, n-cnt) << '\n';
  89.   }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment