1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #include<bits/stdc++.h> using namespace std; using LL = long long;
struct Point { public: int x, y;
Point(int _x, int _y) : x(_x), y(_y) {}
Point operator - (const Point& rhs) { return {x - rhs.x, y - rhs.y}; } };
int dot(const Point& a, const Point& b) { return a.x * b.x + a.y * b.y; }
int cross(const Point& a, const Point& b) { return a.x * b.y - b.x * a.y; }
vector<Point> arr; bool in(Point c) { int n = arr.size(); int ans = 0; for (int i = 0, j = n - 1; i < n; j = i++) { Point a = arr[j], b = arr[i]; if (dot(c - a, c - b) <= 0 && cross(c - a, c - b) == 0) return 0; if (((c.x >= a.x && c.x < b.x) || (c.x >= b.x && c.x < a.x)) && c.y < a.y + 1.0 * (b.y - a.y) / (b.x - a.x) * (c.x - a.x)) { ans = !ans; } } return ans; }
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, q, x, y; cin >> n; for (int i = 0; i < n; ++i) { cin >> x >> y; arr.push_back({x, y}); } cin >> q; int ans = 0; for (int i = 0; i < q; ++i) { cin >> x >> y; if (in({x, y})) ++ans; } cout << ans << endl; return 0; }
|