Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by Елена on 07.01.2020.
- //
- #include <iostream>
- #include <vector>
- #include <algorithm>
- //#include <ostream>
- using namespace std;
- struct point {
- int x, y;
- point() {}
- point(int x, int y) : x(x), y(y) {}
- bool operator==(const point &rhs) const {
- return x == rhs.x && y == rhs.y;
- }
- };
- int rotate_det(const point &a, const point &b, const point &c) {
- return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
- }
- bool left_turn(const point &a, const point &b, const point &c) {
- return rotate_det(a, b, c) > 0;
- }
- int main() {
- int n, x0 ,y0;
- cin >> n >> x0 >> y0;
- vector<point> polygon;
- for (int i = 0; i < n; i++) {
- int x, y;
- cin >> x >> y;
- polygon.emplace_back(x, y);
- }
- if (left_turn(polygon[polygon.size() - 1 - 2], polygon[polygon.size() - 1 - 1], polygon[polygon.size() - 1])
- || left_turn(polygon[0], polygon[1], polygon[2])) {
- reverse(polygon.begin(), polygon.end());
- }
- point p(x0, y0);
- int count = 0;
- bool flag = false;
- for (size_t i = 0; i < polygon.size(); i++) {
- point l = polygon[i];
- point r;
- if(i == polygon.size() - 1) {
- r = polygon[0];
- } else {
- r = polygon[i + 1];
- }
- if (l.y > r.y) {
- swap(l, r);
- }
- if (r.y < p.y || l.y >= p.y) continue;
- int orient = rotate_det(l, r, p);
- if (orient == 0) {
- flag = true;
- break;
- }
- if (orient > 0) {
- count++;
- }
- }
- if(count % 2 ) {
- flag = true;
- }
- if(flag) {
- cout << "YES" << endl;
- } else {
- cout << "NO" << endl;
- }
- }
- /*
- 9 5 2
- 0 2
- 3 0
- 2 2
- 6 1
- 5 6
- 4 4
- 3 5
- 3 3
- 1 3
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement