/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 768.0 KiB
#2 Wrong Answer 1ms 332.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define endl '\n'
#define Endl '\n'

using namespace std;

const int N = 2e5 + 5;
int tc, n, m, a[N];

using T = double;
const T INF = 1e100, EPS = 1e-9, PI = acos(-1.0);

int sign(T x) {
    return (x > EPS) - (x < EPS);
}

typedef struct PT {
    T x, y;
    PT() {};
    PT(T x, T y) : x(x), y(y) {};
    PT(const PT &p) : x(p.x), y(p.y) {};
    PT operator+(const PT &p) const {
        return PT(x + p.x, y + p.y);
    }
    PT operator-(const PT &p) const {
        return PT(x - p.x, y - p.y);
    }
    PT operator*(double c) const {
        return PT(x * c, y * c);
    }
    PT operator/(double c) const {
        return PT(x / c, y / c);
    }
} point;

T cross(PT p, PT q) {
    return p.x * q.y - p.y * q.x;
}

T dot(PT p, PT q) {
    return p.x * q.x + p.y * q.y;
}

//-----------------------------------------------------------------------------
// polygon contains a point
// half-line crossing method
//-----------------------------------------------------------------------------
int contains(vector<PT> ps, PT p) {
    bool in = false;
    for (int i = 0; i < ps.size(); ++i) {
        int j = (i + 1 == ps.size() ? 0 : i + 1);
        point a = ps[i] - p, b = ps[j] - p;
        if (a.y > b.y)
            swap(a, b);
        if (a.y <= 0 && 0 < b.y && cross(a, b) < 0)
            in = !in;
        if (!sign(cross(a, b)) && sign(dot(a, b)) <= 0)
            return 0; // point on the edge
    }
    return in ? -1 : 1; // point in:out the polygon
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); // cout.tie(0);
    cin >> n;
    vector<point> p(n);

    for (int i = 0; i < n; i++) {
        cin >> p[i].x >> p[i].y;
    }
    PT q;
    cin >> q.x >> q.y;
    int res = contains(p, q);
    printf("%d\n", res);
    if (res == -1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1145 Nobita's Love for Shizuka
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-03 04:35:15
Judged At
2024-12-03 04:35:15
Judged By
Score
0
Total Time
1ms
Peak Memory
768.0 KiB