Advertisement
Guest User

704.cpp

a guest
Jun 24th, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <cmath>
  5.  
  6. struct Point {
  7.     int x, y;
  8.    
  9.     int norm2() const {
  10.         return x*x+y*y;
  11.     }
  12. };
  13.  
  14. int cross(Point a, Point b) {
  15.     return a.x * b.y - a.y * b.x;
  16. }
  17.  
  18. bool solve(int side, std::vector<Point> p) {
  19.    
  20.     std::vector<Point> positive, negative;
  21.    
  22.     for (auto& it : p) {
  23.         it.x = 2 * it.x - side;
  24.         it.y = 2 * it.y - side;
  25.         if (it.x == 0 && it.y == 0) {
  26.             return false;
  27.         }
  28.         if (it.x > 0 || (it.x == 0 && it.y > 0)) {
  29.             positive.push_back(Point{it.x, it.y});
  30.         } else {
  31.             negative.push_back(Point{it.x, it.y});
  32.         }
  33.     }
  34.    
  35.     if (p.size() == 1u) {
  36.         return true;
  37.     }
  38.    
  39.     std::sort(positive.begin(), positive.end(), [](const Point& a, const Point& b) {
  40.         return a.y * b.x < b.y * a.x || (a.y * b.x == b.y * a.x && a.norm2() < b.norm2());
  41.     });
  42.    
  43.     std::sort(negative.begin(), negative.end(), [](const Point& a, const Point& b) {
  44.         return a.y * b.x < b.y * a.x || (a.y * b.x == b.y * a.x && a.norm2() < b.norm2());
  45.     });
  46.    
  47.     p.clear();
  48.     p.insert(p.end(), positive.begin(), positive.end());
  49.     p.insert(p.end(), negative.begin(), negative.end());
  50.  
  51.     const int n = p.size();
  52.     p.push_back(p[0]);
  53.     for (int i = 1; i <= n; ++i) {
  54.         if (cross(p[i-1], p[i]) < 0) {
  55.             return true;
  56.         }
  57.     }
  58.     return false;
  59. }
  60.  
  61. int main() {
  62.    
  63.     int side, n;
  64.     scanf("%d %d", &side, &n);
  65.    
  66.     std::vector<Point> p;
  67.     for (int i = 0; i < n; ++i) {
  68.         int x, y;
  69.         scanf("%d %d", &x, &y);
  70.         p.push_back(Point{x,y});
  71.     }
  72.     printf(solve(side, p) ? "YES\n" : "NO\n");
  73.    
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement