SHARE
TWEET

Untitled

a guest Dec 16th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. struct tower {
  8.     int x, y;
  9. };
  10.  
  11. double y_at(tower a, tower b, int x) {
  12.     double dx = b.x - a.x,
  13.            dy = b.y - a.y;
  14.     return (x - a.x) * (dy / dx) + a.y;
  15. }
  16.  
  17. int main() {
  18.     int n, m;
  19.     cin >> n;
  20.     vector<tower> a, b;
  21.     for (int i = 0; i < n; i++) {
  22.         tower t;
  23.         cin >> t.x >> t.y;
  24.         a.push_back(t);
  25.     }
  26.     cin >> m;
  27.     for (int i = 0; i < m; i++) {
  28.         tower t;
  29.         cin >> t.x >> t.y;
  30.         b.push_back(t);
  31.     }
  32.     for (int i = 0; i < m; i++) {
  33.         double mcy = -1.0;
  34.         for (int j = 0; j < n; j++) {
  35.             double cy = b[i].y;
  36.             int ax = min(a[j].x, b[i].x),
  37.                 bx = max(a[j].x, b[i].x);
  38.             for (int k = 0; k < m; k++)
  39.                 if (b[k].x > ax && b[k].x < bx) {
  40.                     double ky = y_at(b[i], a[j], b[k].x);
  41.                     if (ky < b[k].y)
  42.                         cy = y_at(b[k], a[j], b[i].x);
  43.                 }
  44.             if (mcy < 0.0 || cy < mcy)
  45.                 mcy = cy;
  46.         }
  47.         printf("%.2f\n", mcy - b[i].y);
  48.     }
  49.     return 0;
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top