Question link: http://acm.hrbust.edu.cn/index.php? M = problemset & A = showproblem & problem_id = 1291.
Analysis: because it is a convex polygon, you only need to calculate the cross product for each edge.
VectorPAndQThen their Cross ProductPXQIt has the following properties:
1.PXQ> 0PInQClockwise direction;
2.PXQ<0, thenPInQIn a counter-clockwise direction;
3.PXQ= 0, thenPAndQCollinearity, which may be the same direction or reverse direction;
# Include <iostream> # include <string> # include <cstring> # include <algorithm> # include <cstdio> # include <cmath> # include <iomanip> using namespace STD; const int maxn = 100000; struct point {int X, Y; void read () {CIN> x> Y ;}rt, F [maxn]; double Cross (point P0, Point P1, point P2) {// return (p1.x-forwarded X) * (p2.y-forwarded y)-(p2.x-forwarded X) * (p1.y-policy);} int main () {int N; while (CIN> N) {RT. read (); For (INT I = 0; I <n; ++ I) f [I]. read (); F [N] = f [0]; bool OK = true; For (INT I = 0; I <n; ++ I) if (Cross (F [I], F [I + 1], RT) <0) {// outside the edge, OK = false; break;} If (OK) puts ("yes"); else puts ("no");} return 0 ;}