After finding the convex hull, the violent enumeration edge is $check$, note that the convex hull is a line (or two lines) of the case to output $no$
#include <cmath> #include <cstdio> #include <cstring> #include <algorithm> #define N 1003#define Read (x) x = Getint () using namespace Std;inline int getint () {int k = 0, fh = 1; char c = GetChar (); for (C < ' 0 ' | | C & Gt ' 9 '; c = GetChar ()) if (c = = '-') FH = -1;for (; c >= ' 0 ' && C <= ' 9 '; c = GetChar ()) K = k * + C-' 0 '; return k * FH;} struct point {int x, y; Point (int _x = 0, int _y = 0): X (_x), Y (_y) {}};inline int dcmp (int x) {return x = = 0? 0: (x < 0? -1:1);} Point operator-(point A, point B) {return point (a.x-b.x, a.y-b.y);} BOOL operator = = (Point A, point B) {return a.x = = b.x && A.y = = b.y;} inline int Cross (point A, point B) {return a.x * b.y-a.y * b.x;} inline int Dot (point A, point B) {return a.x * b.x + a.y * B.Y;} inline bool Jiao (point D1, point D2, Point D3, point D4) {return (DCMP (D4-D3, d1-d3)) ^ dcmp (Cross (D4-D3, D2- D3)) = =-2) && (dcmp (d2-d1, d3-d1) ^ dcmp (Cross (D2-D1, d4-d1)) = = -2);} inline bool Onin (Point-D1, point-D2, Point-D3) {return cross (d2-d1, d3-d1) = = 0 && Dot (d2-d1, D3-D1) < 0;} Point A[n], Tb[n];int N, T, top;inline bool CMP (point D1, point D2) {return d1.y = d2.y? d1.x < D2.x:d1.y < D2.Y ;} inline void Mktb () {top = 2;tb[1] = a[1];tb[2] = a[2];for (int i = 3; I <= n; ++i) {while (Cross (A[i]-tb[top], Tb[top] -tb[top-1]) >= 0 && top > 1)--top;tb[++top] = A[i];} int k = Top;tb[++top] = a[n-1];for (int i = n-2; I >= 1; i) {while (Cross (A[i]-tb[top], Tb[top]-tb[top-1]) = 0 && top > K)--top;tb[++top] = A[i];}} inline bool Check (point D1, point D2) {for (int i = 1; I <= n; ++i) if (Onin (A[i], D1, D2)) return 1;return 0;} int main () {read (T); t--{read (n); for (int i = 1; I <= n; ++i) read (a[i].x), read (A[I].Y); sort (A + 1, a + n + 1, c MP); MKTB (); bool PD = 1;for (int i = 2; I <= top; ++i) if (!check (Tb[i], tb[i-1]) {PD = 0;break;} (PD = = 0 | | top = = 3)? Puts ("NO"): Puts ("YES");} return 0;}
That's it.
"POJ 1228" Grandpa ' s Estate convex bag