Mlxa

TEAMBOOK Теодор Рузвельт

Nov 1st, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using ld = long double;
  3. using ll = long long;
  4. #define double ld
  5. #define long ll
  6. using namespace std;
  7.  
  8. int cmp(double a, double b) {
  9.     const double EPS = 1e-9;
  10.     if (abs(a - b) <= EPS) {
  11.         return 0;
  12.     } else if (a < b) {
  13.         return -1;
  14.     } else {
  15.         return +1;
  16.     }
  17. }
  18.  
  19. struct Point {
  20.     ld x, y;
  21.     Point(ld a, ld b) {
  22.         x = a;
  23.         y = b;
  24.     }
  25.     Point() {
  26.         x = 0;
  27.         y = 0;
  28.     }
  29. };
  30. istream &operator>>(istream &in, Point &p) {
  31.     int x, y;
  32.     in >> x >> y;
  33.     p.x = x;
  34.     p.y = y;
  35.     return in;
  36. }
  37. ostream &operator<<(ostream &out, Point p) {
  38.     return out << p.x << " " << p.y;
  39. }
  40. ld operator%(Point a, Point b) {
  41.     return a.x * b.y - a.y * b.x;
  42. }
  43. Point operator-(Point a, Point b) {
  44.     return {a.x - b.x, a.y - b.y};
  45. }
  46. Point operator+(Point a, Point b) {
  47.     return {a.x + b.x, a.y + b.y};
  48. }
  49.  
  50. const int N = 2e5;
  51. int n;
  52. Point p[N];
  53.  
  54. int turn(Point a, Point b, Point c) {
  55.     return cmp((b - a) % (c - a), 0);
  56. }
  57.  
  58. bool query(Point x) {
  59.     bool precond = turn(p[0], p[1], x) >= 0 && turn(p[0], p[n - 1], x) <= 0;
  60.     if (!precond) {
  61.         return false;
  62.     }
  63.     int l = 0, r = n - 1;
  64.     while (r - l > 1) {
  65.         assert(turn(p[0], p[l], x) >= 0);
  66.         assert(turn(p[0], p[r], x) <= 0);
  67.         assert(turn(p[0], p[l], p[r]) >= 0);
  68.         int m = (l + r) / 2;
  69.         if (turn(p[0], p[m], x) >= 0) {
  70.             l = m;
  71.         } else {
  72.             r = m;
  73.         }
  74.     }
  75.     assert(turn(p[0], p[l], x) >= 0);
  76.     assert(turn(p[0], p[r], x) <= 0);
  77.     assert(turn(p[0], p[l], p[r]) >= 0);
  78.     return turn(p[l], p[r], x) >= 0;
  79. }
  80.  
  81. int main() {
  82. #ifdef LC
  83.     assert(freopen("input.txt", "r", stdin));
  84. #else
  85.     assert(freopen("theodore.in", "r", stdin));
  86.     assert(freopen("theodore.out", "w", stdout));
  87. #endif
  88.     ios::sync_with_stdio(0);
  89.     cin.tie(0);
  90.     cout << fixed << setprecision(10);
  91.    
  92.     int m, k;
  93.     cin >> n >> m >> k;
  94.     for (int i = 0; i < n; ++i) {
  95.         cin >> p[i];
  96.     }
  97.     p[n] = p[0];
  98.    
  99.     int answer = 0;
  100.    
  101.     for (int i = 0; i < m; ++i) {
  102.         Point q;
  103.         cin >> q;
  104.         bool r = query(q);
  105.         answer += r;
  106.     }
  107.    
  108.     if (answer >= k) {
  109.         cout << "YES\n";
  110.     } else {
  111.         cout << "NO\n";
  112.     }
  113.     return 0;
  114. }
Add Comment
Please, Sign In to add comment