Task: | Point in Polygon |
Sender: | hungdojan |
Submission time: | 2024-11-11 16:22:10 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.01 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; #define I_2D(row, col, width) ((row) * (width) + (col)) #define PRINT_ARR(arr, n) \ do { \ for (int i = 0; i < n; i++) { \ cout << arr[i] << " "; \ } \ cout << "\n"; \ } while (0) #define PRINT_VEC_ARR(v, n) \ do { \ for (int i = 0; i < n; i++) { \ cout << i << ": "; \ for (auto item : v[i]) { \ cout << item << " "; \ } \ cout << endl; \ } \ } while (0) #define endl '\n'; typedef long long ll; typedef complex<ll> P; #define X real() #define Y imag() #define CP(a, b, c) ((conj(c - a) * (c - b)).Y) bool cmp(const P &a, const P &b) { return (a.X == b.X) ? (a.Y < b.Y) : (a.X < b.X); } bool is_on_the_line(const P a, const P b, const P p) { vector<P> pp{a, b, p}; sort(pp.begin(), pp.end(), cmp); return pp[1] == p; } bool in_range(P a, P b, P p) { if (a.Y > b.Y) { auto tmp = a; a = b; b = tmp; } return a.Y < p.Y && p.Y < b.Y; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; P arr[n]; ll x, y; for (int i = 0; i < n; i++) { cin >> x >> y; arr[i] = {x, y}; } bool boundary = false; for (int i = 0; i < m; i++) { cin >> x >> y; P point = {x, y}; boundary = false; int edges = 0; for (int j = 0; j < n; j++) { P a = arr[j], b = arr[(j + 1) % n]; if (CP(a, b, point) == 0 && is_on_the_line(a, b, point)) { boundary = true; break; } // if (in_range(a, b, point) && (a.X < point.X || b.X < point.X)) { if (a.X <= point.X && point.X < b.X && CP(a, b, point) < 0) { edges++; } else if (b.X <= point.X && point.X < a.X && CP(b, a, point) < 0) { edges++; } } if (boundary) { cout << "BOUNDARY" << endl; } else if (edges & 1) { cout << "INSIDE" << endl; } else { cout << "OUTSIDE" << endl; } } return 0; }
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 ... |
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 ... |
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 |