Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- struct Point {
- int x, y;
- int norm2() const {
- return x*x+y*y;
- }
- };
- int cross(Point a, Point b) {
- return a.x * b.y - a.y * b.x;
- }
- bool solve(int side, std::vector<Point> p) {
- std::vector<Point> positive, negative;
- for (auto& it : p) {
- it.x = 2 * it.x - side;
- it.y = 2 * it.y - side;
- if (it.x == 0 && it.y == 0) {
- return false;
- }
- if (it.x > 0 || (it.x == 0 && it.y > 0)) {
- positive.push_back(Point{it.x, it.y});
- } else {
- negative.push_back(Point{it.x, it.y});
- }
- }
- if (p.size() == 1u) {
- return true;
- }
- std::sort(positive.begin(), positive.end(), [](const Point& a, const Point& b) {
- return a.y * b.x < b.y * a.x || (a.y * b.x == b.y * a.x && a.norm2() < b.norm2());
- });
- std::sort(negative.begin(), negative.end(), [](const Point& a, const Point& b) {
- return a.y * b.x < b.y * a.x || (a.y * b.x == b.y * a.x && a.norm2() < b.norm2());
- });
- p.clear();
- p.insert(p.end(), positive.begin(), positive.end());
- p.insert(p.end(), negative.begin(), negative.end());
- const int n = p.size();
- p.push_back(p[0]);
- for (int i = 1; i <= n; ++i) {
- if (cross(p[i-1], p[i]) < 0) {
- return true;
- }
- }
- return false;
- }
- int main() {
- int side, n;
- scanf("%d %d", &side, &n);
- std::vector<Point> p;
- for (int i = 0; i < n; ++i) {
- int x, y;
- scanf("%d %d", &x, &y);
- p.push_back(Point{x,y});
- }
- printf(solve(side, p) ? "YES\n" : "NO\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement