#include #include struct Point { double x; double y; }; double orientation(const Point &A, const Point &B, const Point &C) { return (B.x - A.x) * (C.y - A.y) - (C.x - A.x) * (B.y - A.y); } double distance(const Point &A, const Point &B) { double dx = B.x - A.x; double dy = B.y - A.y; return dx * dx + dy * dy; } bool in_triangle(const Point &A, const Point &B, const Point &C, const Point &S) { double o1 = orientation(A, B, S); double o2 = orientation(B, C, S); double o3 = orientation(C, A, S); if ((o1 > 0 && o2 > 0 && o3 > 0) || (o1 < 0 && o2 < 0 && o3 < 0)) { return true; } return false; } bool in_convex_hull(const std::vector &CH, const Point &S) { const int n = CH.size(); if (orientation(CH[0], CH[1], S) < 0 || orientation(CH[0], CH[n - 1], S) < 0) { return false; } int l = 1; int r = n - 1; while (r - l > 1) { int m = l + (r - l) / 2; int o = orientation(CH[0], CH[m], S); if (o > 0) { r = m; } else if (o < 0) { l = m; } else { if (distance(CH[0], S) < distance(CH[0], CH[m])) { return true; } else { return false; } } } if (in_triangle(CH[0], CH[l], CH[r], S)) { return true; } return false; } int main(int argc, const char *argv[]) { return 0; }