Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- struct Point {
- double x, y;
- Point(double x0 = 0, double y0 = 0)
- {
- x = x0;
- y = y0;
- }
- };
- istream & operator >> (istream & in, Point & P) {
- in >> P.x >> P.y;
- return in;
- }
- struct Vector {
- double x, y;
- Vector(double x0, double y0) {
- x = x0;
- y = y0;
- }
- Vector(Point A, Point B) {
- x = B.x - A.x;
- y = B.y - A.y;
- }
- };
- double vectMultipl(Vector a, Vector b) {
- return a.x * b.y - b.x * a.y;
- }
- double scalarMultipl(Vector a, Vector b) {
- return a.x * b.x + b.y * a.y;
- }
- bool onSegment(Point C, Point A, Point B) {
- Vector AB = Vector(A, B);
- Vector AC = Vector(A, C);
- Vector BA = Vector(B, A);
- Vector BC = Vector(B, C);
- if (vectMultipl(AB, AC) == 0 && AB.x * AC.x >= 0 && AB.y * AC.y >= 0 &&
- vectMultipl(BA, BC) == 0 && BA.x * BC.x >= 0 && BA.y * BC.y >= 0)
- return true;
- else
- return false;
- }
- int main() {
- int n;
- Point O;
- cin >> n >> O;
- Point polygon[n];
- for (int i = 0; i < n; i++)
- cin >> polygon[i];
- double angle = 0;
- for (int i = 0; i < n; i++) {
- if (onSegment(O, polygon[i], polygon[(i + 1) % n])) {
- cout << "YES";
- return 0;
- }
- Vector OPi = Vector(O, polygon[i]);
- Vector OPi1 = Vector(O, polygon[(i + 1) % n]);
- angle += atan2(vectMultipl(OPi, OPi1), scalarMultipl(OPi, OPi1));
- }
- if (abs(abs(angle) - 2 * M_PI) <= 0.1)
- cout << "YES";
- else
- cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement