The main topic is
There are some points, and then we want to use a hexagonal star to cover any of these points in a straight line. And the convex hull area of these points must satisfy less than a certain value
The center point and radius of the hexagonal star have been given.
is a matter of judgement.
The first thing to tell is whether all the dots are in the hex star.
We looked at the shape and found that it was a figure of two triangles.
Then just determine if a point is within a triangle
You can use the cross product here.
Then a convex hull is obtained for all points.
Find an area
and see if the edges of these convex hull are within the hexagonal star.
Viewing the graph, you can see that it consists of 12 short-term segments that form a boundary
So see if the edges are in the hexagonal star shape. Simply determine if an edge intersects these boundary specifications
The code is as follows.
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include < algorithm> #include <cstdlib> #include <cmath> #include <map> #include <sstream> #include <queue> #include <vector> #define MAXN 111111 #define MAXM 211111 #define EPS 1e-8 #define INF 1000000001 usin
G namespace Std;
int dblcmp (double d) {if (Fabs (d) < EPS) return 0; Return d > EPS?
1:-1;
} struct Point {double x, y;
Point () {}-point (double _x, double _y): X (_x), Y (_y) {};
void input () {scanf ("%lf%lf", &x, &y);
} double dot (point P) {return x * p.x + y * P.Y;
} double distance (point P) {return hypot (x-p.x, Y-P.Y);
} point Sub (point P) {return point (x-p.x, y-p.y);
} double det (point p) {return x * p.y-y * p.x; } bool operator < (point a) const {return dblcmp (a.x-x) = = 0?
DBLCMP (Y-A.Y) < 0:x < a.x;
}}P[MAXN], hg[15];
struct Line {point A, B;
Line () {} line (point _a, point _b) {a = _a; b = _b;}
int segcrossseg (line v) {int d1 = dblcmp (B.sub (a). Det (V.a.sub (a)));
int d2 = DBLCMP (B.sub (a). Det (V.b.sub (a)));
int d3 = DBLCMP (V.b.sub (V.A). Det (A.sub (V.A)));
int d4 = dblcmp (V.b.sub (V.A). Det (B.sub (V.A)));
if (d1 ^ d2) = =-2 && (d3 ^ d4) = =-2) return 2;
return (D1 = = 0 && dblcmp (v.a.sub (a). dot (v.a.sub (b))) <=0 | |
D2 = = 0 && dblcmp (v.b.sub (a). dot (v.b.sub (b))) <=0 | |
D3 = = 0 && dblcmp (a.sub (V.A). Dot (A.sub (V.B))) <= 0 | |
D4 = = 0 && dblcmp (b.sub (V.A). Dot (B.sub (V.B))) <= 0);
}}seg[13], tri[2][3];
struct polygon {int n;
Point P[MAXN];
Line L[MAXN];
Double area;
void input () {for (int i = 0; i < n; i++) p[i].input (); } void Getline() {for (int i = 0; i < n; i++) L[i] = line (P[i], p[(i + 1)% n]);
} void Getarea () {area = 0;
int a = 1, b = 2;
while (b <= n-1) {area + = P[a].sub (p[0]). Det (p[b].sub (p[0)));
a++;
b++;
} area = fabs (area)/2;
}}convex;
BOOL Conpoint (point P[],int N) {for (int i = 1; i < n; i++) if (dblcmp (p[i].x-p[0].x)! = 0 | |
DBLCMP (p[i].y-p[0].y)! = 0) return false;
return true; } bool Conline (point P[],int N) {for (int i = 2; i < n; i++) if (dblcmp (P[1].sub (p[0)). Det (p[i].sub (p[0)))
)! = 0) return false;
return true;
} void Getconvex (Point p[], int. N, Point res[], int& resn) {resn = 0;
if (Conpoint (P, N)) {res[resn++] = p[0];
Return
} sort (p, p + N);
if (Conline (p,n)) {res[resn++] = p[0];
res[resn++] = p[n-1]; Return; } for (int i = 0; i < n;) if (Resn < 2 | | dblcmp (RES[RESN-1].SUB (res[resn-2]). Det (P[i].sub (res[resn
-1]))) > 0) res[resn++] = p[i++];
else--RESN;
int top = resn-1; for (int i = n-2; I >= 0;) if (RESN < top + 2 | | dblcmp (RES[RESN-1].SUB (res[resn-2]). Det (P[i].sub (res[
Resn-1]))) > 0) res[resn++] = p[i--];
else--RESN;
resn--;
} int n;
BOOL Intriangle (point x) {int tmp = 2; for (int i = 0, i < 2; i++) {for (int j = 0; J < 3; J + +) if (dblcmp (Tri[i][j].a.sub (x). Det (Tri I
[J].b.sub (x))) > 0) {tmp--;
Break
}} return tmp > 0;
} int main () {double sx, sy, S, R;
while (scanf ("%lf%lf", &SX, &sy)! = EOF) {scanf ("%d", &n);
for (int i = 0; i < n; i++) p[i].input ();
Getconvex (P, N, CONVEX.P, CONVEX.N);
Convex.getline (); Convex.getarea ();
scanf ("%lf%lf", &r, &s);
Double SThree = sqrt (3.0);
Hg[0] = point (SX, SY + sthree * R);
HG[1] = Point (SX + R/2, sy + sthree * R/2);
HG[2] = Point (SX + R * 3.0/2, sy + sthree * R/2);
HG[3] = Point (SX + R, SY);
HG[4] = Point (SX + R * 3.0/2, Sy-sthree * R/2);
HG[5] = Point (SX + R/2, Sy-sthree * R/2);
HG[6] = point (SX, Sy-sthree * R);
HG[7] = point (Sx-r/2, Sy-sthree * R/2);
HG[8] = Point (Sx-r * 3.0/2, Sy-sthree * R/2);
HG[9] = point (Sx-r, SY);
HG[10] = Point (Sx-r * 3.0/2, sy + sthree * R/2);
HG[11] = point (Sx-r/2, sy + sthree * R/2);
Tri[0][0] = line (hg[0], hg[4]);
TRI[0][1] = line (Hg[4], hg[8]);
TRI[0][2] = line (Hg[8], hg[0]);
Tri[1][0] = line (hg[2], hg[6]);
TRI[1][1] = line (Hg[6], hg[10]);
TRI[1][2] = line (hg[10], hg[2]); for (int i = 0; i < 12;
i++) Seg[i] = line (Hg[i], hg[(i + 1)% 12]);
int flag = 1;
for (int i = 0; i < n; i++) {if (!intriangle (P[i])) {flag = 0;
Break
}} for (int i = 0; i < n; i++) {if (flag = = 0) break;
for (int j = 0; J < CONVEX.N; J + +) if (Seg[i].segcrossseg (convex.l[j]) = = 2) {
Flag = 0;
Break }} if (flag) {if (dblcmp (3.0 * SThree * R * r-convex.area-s) > 0) puts ("Succeed
ed. ");
Else puts ("Failed.");
} else puts ("Failed.");
} return 0; }