fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct Pt {
  5. long long x, y;
  6. };
  7. long long cross(Pt a, Pt b, Pt c) {
  8. return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
  9. }
  10. bool on_seg(Pt a, Pt b, Pt p) {
  11. if (cross(a, b, p) != 0) return false;
  12. return p.x >= min(a.x, b.x) && p.x <= max(a.x, b.x) &&
  13. p.y >= min(a.y, b.y) && p.y <= max(a.y, b.y);
  14. }
  15.  
  16. void solve() {
  17. int n, m;
  18. if (!(cin >> n >> m)) return;
  19.  
  20. vector<Pt> p(n);
  21. for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y;
  22.  
  23. while (m--) {
  24. Pt q;
  25. cin >> q.x >> q.y;
  26.  
  27. bool bnd = false;
  28. int cnt = 0;
  29.  
  30. for (int i = 0; i < n; i++) {
  31. Pt a = p[i];
  32. Pt b = p[(i + 1) % n];
  33.  
  34. if (on_seg(a, b, q)) {
  35. bnd = true;
  36. break;
  37. }
  38. if (a.y > b.y) swap(a, b);
  39. if (q.y >= a.y && q.y < b.y && cross(q, a, b) > 0) {
  40. cnt++;
  41. }
  42. }
  43.  
  44. if (bnd) cout << "BOUNDARY"<<'\n';
  45. else if (cnt % 2 == 1) cout << "INSIDE"<<'\n';
  46. else cout << "OUTSIDE"<<'\n';
  47. }
  48. }
  49.  
  50. int main() {
  51. ios_base::sync_with_stdio(0); cin.tie(0);
  52. solve();
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty