Task: | Point in Polygon |
Sender: | ZDHKLV |
Submission time: | 2024-11-11 16:52:30 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.02 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
Code
#include <bits/stdc++.h> using namespace std; typedef long long C; typedef complex<C> P; #define X real() #define Y imag() const long long INF = 1e9 + 7; long long cross(P a, P b, P c) { long long cp = (conj(b-a)*(c-a)).Y; return (cp > 0) - (cp < 0); } bool comp(const P &a, const P &b) { return (a.X == b.X) ? (a.Y < b.Y) : (a.X < b.X); } bool mid(P a, P b, P c) { vector<P> v = {a, b, c}; sort(v.begin(), v.end(), comp); return (v[1] == c); } bool check(P a, P b, P c, P d) { long long b1 = cross(a, b, c); long long b2 = cross(a, b, d); long long b3 = cross(c, d, a); long long b4 = cross(c, d, b); if (b1 * b2 < 0 && b3 * b4 < 0) return true; if (b3 == 0 && mid(c, d, a) && b4 < 0) return true; if (b4 == 0 && mid(c, d, b) && b3 < 0) return true; return false; } int main() { int n, m; cin >> n >> m; vector<pair<long long, long long>> vertices(n); vector<pair<long long, long long>> points(m); for (int i = 0; i < n; i++) { long long a, b; cin >> a >> b; vertices[i] = {a, b}; } for (int i = 0; i < m; i++) { long long a, b; cin >> a >> b; points[i] = {a, b}; } vector<P> polygon; for (long long i = 0; i < n; i++) polygon.push_back({vertices[i].first, vertices[i].second}); polygon.push_back(polygon[0]); for (long long i = 0; i < m; i++) { P point = {points[i].first, points[i].second}; P infinity = {INF, INF}; long long intersections = 0; bool boundary = 0; for (long long j = 0; j < n; j++) { long long q = cross(polygon[j], polygon[j+1], point); if (q == 0 && mid(polygon[j], polygon[j+1], point)) { boundary = true; break; } intersections += check(polygon[j], polygon[j+1], point, infinity); } if (boundary) cout << "BOUNDARY" << endl; else cout << (intersections & 1 ? "INSIDE" : "OUTSIDE") << endl; } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
100 1000 -7 -19 91 77 100 100 64 60 ... |
correct output |
---|
INSIDE OUTSIDE INSIDE INSIDE INSIDE ... |
user output |
---|
INSIDE OUTSIDE INSIDE INSIDE INSIDE ... Truncated |
Test 2
Verdict: ACCEPTED
input |
---|
1000 1000 365625896 -113418831 278762563 38777445 250367343 -96991975 175866909 -129766978 ... |
correct output |
---|
OUTSIDE OUTSIDE INSIDE OUTSIDE OUTSIDE ... |
user output |
---|
OUTSIDE OUTSIDE INSIDE OUTSIDE OUTSIDE ... Truncated |
Test 3
Verdict: ACCEPTED
input |
---|
4 1 1 5 5 5 5 1 1 1 ... |
correct output |
---|
INSIDE |
user output |
---|
INSIDE |
Test 4
Verdict: ACCEPTED
input |
---|
4 1 1 5 5 5 5 1 1 1 ... |
correct output |
---|
OUTSIDE |
user output |
---|
OUTSIDE |
Test 5
Verdict: ACCEPTED
input |
---|
4 1 1 100 2 50 1 20 0 50 ... |
correct output |
---|
INSIDE |
user output |
---|
INSIDE |
Test 6
Verdict: ACCEPTED
input |
---|
8 1 0 0 0 2 1 1 2 2 ... |
correct output |
---|
INSIDE |
user output |
---|
INSIDE |
Test 7
Verdict: ACCEPTED
input |
---|
4 4 0 0 3 0 3 4 0 4 ... |
correct output |
---|
INSIDE BOUNDARY OUTSIDE BOUNDARY |
user output |
---|
INSIDE BOUNDARY OUTSIDE BOUNDARY |
Test 8
Verdict: ACCEPTED
input |
---|
6 1 0 0 0 2 3 1 2 2 ... |
correct output |
---|
INSIDE |
user output |
---|
INSIDE |
Test 9
Verdict: ACCEPTED
input |
---|
3 1 0 0 1 1000000000 -3 0 1 1 |
correct output |
---|
OUTSIDE |
user output |
---|
OUTSIDE |
Test 10
Verdict: ACCEPTED
input |
---|
3 1 -100000 0 -1000000000 -999999999 1000000000 1000000000 0 0 |
correct output |
---|
OUTSIDE |
user output |
---|
OUTSIDE |
Test 11
Verdict: ACCEPTED
input |
---|
3 1 -100000 0 -999999999 -1000000000 1000 1000 0 0 |
correct output |
---|
INSIDE |
user output |
---|
INSIDE |
Test 12
Verdict: ACCEPTED
input |
---|
4 1 -4 1 -6 1 -6 -1 -4 -1 ... |
correct output |
---|
INSIDE |
user output |
---|
INSIDE |
Test 13
Verdict: ACCEPTED
input |
---|
3 1 0 10 0 -10 10 0 1 0 |
correct output |
---|
INSIDE |
user output |
---|
INSIDE |