Stable definition:
When the center of gravity of the polygon glass plate is perpendicular to the horizontal plane, the vertical foot falls on the line segment of the supporting edge (excluding the line segment endpoint ).
Enumeration of polygon support edges:
As a concave polygon may appear, the supported edges that can be selected include all edges of the convex hull of the polygon.
Ideas:
Calculate the center of gravity first, and then the convex hull. enumerate each side of the convex hull to determine whether it can be a support side. (Note that the intersection of the center of gravity to a support edge is invalid at the endpoint)
Code:
/* Center of Gravity + convex hull * // * AC code: 187 Ms */# include <iostream> # include <cstdio> # include <algorithm> # define maxn 50005 using namespace STD; /* ===================================================== ===============* \ | Graham convex hull O (N * logn) | call: Nr = Graham (PNT, int N, Res); Res [] is a convex packet point set; \ * =================================================== ============= */struct point {Double X, Y ;}; struct point PNT [maxn], Res [maxn], center; int n, m; bool mult (point sp, poi Nt ep, point OP) {return (sp. x-op.x) * (Ep. y-op.y)> = (Ep. x-op.x) * (sp. y-op.y);} bool operator <(const point & L, const point & R) {return L. Y <R. Y | (L. y = R. Y & L. x <R. x);} int Graham (point PNT [], int N, point res []) // note that the storage starts from 0 {int I, Len, K = 0, top = 1; sort (PNT, PNT + n); If (n = 0) return 0; Res [0] = PNT [0]; If (n = 1) return 1; Res [1] = PNT [1]; If (n = 2) return 2; Res [2] = PNT [2]; for (I = 2; I <n; I ++) {While (top & mult (P NT [I], Res [Top], Res [Top-1]) Top --; Res [++ top] = PNT [I];} Len = top; res [+ TOP] = PNT [N-2]; for (I = n-3; I> = 0; I --) {While (top! = Len & mult (PNT [I], Res [Top], Res [Top-1]) Top --; Res [++ top] = PNT [I];} return top; // return the number of center points in the convex hull} // ------------------------------------------------------------ // calculate the polygon Center of Gravity // init: PNT [] clockwise (or counterclockwise) sort order; // call: res = bcenter (PNT, n); // ------------------------------------------------------------ // point bcenter (point PNT [], int N) {point P, S; Ouble TP, Area = 0, tpx = 0, TPY = 0; p. X = PNT [0]. x; p. y = PNT [0]. y; For (INT I = 1; I <= N; ++ I) {// point: 0 ~ N-1 S. x = PNT [(I = N )? 0: I]. X; S. Y = PNT [(I = N )? 0: I]. y; TP = (P. x * s. y-s. x * P. y); area + = TP/2; tpx + = (P. X + S. x) * TP; TPY + = (P. Y + S. y) * TP; p. X = S. x; p. y = S. y;} s. X = tpx/(6 * area); S. y = TPY/(6 * area); Return s;} void Init () {int I; scanf ("% d", & N); for (I = 0; I <n; I ++) scanf ("% lf", & PNT [I]. x, & PNT [I]. y); Center = bcenter (PNT, n); M = Graham (PNT, N, Res);} double MUL (point P1, point P2) // Point product {return p1.x * p2.x + p1.y * p2.y;} bool judge (point P1, point P2) // determine whether the two angles are acute angles {point a, B; double X1, x2, Y1, Y2, XO, yo; X1 = p1.x; Y1 = p1.y; x2 = p2.x; y2 = p2.y; XO = center. x; yo = center. y;. X = (x2-x1);. y = (y2-y1); B. X = (xo-x1); B. y = (yo-y1); If (MUL (a, B) <= 0) return false;. X = (x1-x2);. y = (y1-y2); B. X = (xo-x2); B. y = (yo-y2); If (MUL (a, B) <= 0) return false; return true;} void solve () {int I, ANS = 0; for (I = 0; I <M-1; I ++) ans + = judge (RES [I], Res [I + 1]); ans + = judge (RES [M-1], Res [0]); // printf ("& %. 3lf %. 3lf \ n ", center. x, center. y); printf ("% d \ n", ANS);} int main () {int t; scanf ("% d", & T); While (t --) {Init (); solve ();} return 0 ;}