Topic Link: Click to open the link
The main topic: given the coordinates of n points, now requires a square, completely surrounded by n points, and the smallest square area, the smallest square area.
The expression cannot understand why the area changes with the angle is a single-peak function, waiting for Daniel to tell you that,
If the area changes with the angle is a single-peak function, then naturally you can think of three points, according to the question asked to find the smallest square area, if the square is parallel to the x-axis, then the square area is the maximum distance of x *y maximum distance. Then rotate the square, in 0-90 degrees will always find a square area of the minimum,, but the rotation of the square is more troublesome, we can consider rotating coordinate system, will do coordinate system rotation 0-90 degrees, according to the angle of rotation to recalculate the coordinates of the points, and then find the difference between the X and Y, calculate the area.
Because it is a single-peak function, it uses a three-point angle to find a minimum area.
Note: The eqs of the three points to be very small,,,,,
Angular rotation Formula x = X*cos (j)-Y*sin (j); y = X*sin (j) + Y*cos (j);
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm>using namespace std; Define EQS 1e-12#define INF 0x3f3f3f3f#define PI acos ( -1.0) struct node{double x, y;} P[35];int N;d ouble Maxx, Minx, Maxy, Miny;d ouble F (double j) {int i; Double x, y; Maxx = Maxy =-inf; Minx = Miny = INF; for (i = 0; i < n; i++) {x = P[i].x*cos (j)-P[i].y*sin (j); y = P[i].x*sin (j) + P[i].y*cos (j); Maxx = max (maxx,x); Minx = min (minx,x); Maxy = max (maxy,y); miny = min (miny,y); } return Max (Maxx-minx,maxy-miny);} int main () {int T, I; scanf ("%d", &t); while (t--) {scanf ("%d", &n); for (i = 0; i < n; i++) {scanf ("%lf%lf", &p[i].x, &P[I].Y); } Double low = 0.0, MID1, mid2, high = pi/2.0; while (Low + EQs < high) {MID1 = (low + high)/2.0; Mid2 = (mid1 + high)/2.0; if (f (MID1) > F (mid2)) low = MID1; else high = Mid2; } low = f (low); printf ("%.2lf\n", Low*low); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Poj3301--texas Trip (minimum square overlay)