Given some vertices, find the smallest square to cover all vertices.
Idea: rotate a square with a rotation angle (0 ~ 90), using the three-way method, find the smallest square (correctness is not proved ).
# Include <iostream> <br/> # include <string> <br/> # include <cstdio> <br/> # include <cmath> <br/> using namespace STD; <br/> # define ESP 1e-10 <br/> # define maxcost 99999 <br/> class point <br/>{< br/> Public: <br/> double X, y; <br/>}; <br/> point P [35]; <br/> int N; <br/> double check (double PI) <br/>{< br/> double Ymax =-1 * maxcost, ymin = maxcost, xmax =-1 * maxcost, xmin = maxcost, tempx, Tempy; <br/> int I; <br/> for (I = 0; I <n; I ++) <Br/>{< br/> tempx = P [I]. x * Cos (PI)-P [I]. y * sin (PI); <br/> Tempy = P [I]. x * sin (PI) + P [I]. y * Cos (PI); <br/> xmax = xmax> tempx? Xmax: tempx; <br/> xmin = xmin <tempx? Xmin: tempx; <br/> Ymax = Ymax> Tempy? Ymax: Tempy; <br/> ymin = ymin <Tempy? Ymin: Tempy; <br/>}< br/> double Len = Ymax-ymin> xmax-xmin? Ymax-ymin: xmax-xmin; <br/> return Len; <br/>}< br/> int main () <br/>{< br/> int t, i; <br/> CIN> T; <br/> while (t --) <br/>{< br/> CIN> N; <br/> for (I = 0; I <n; I ++) <br/> CIN> P [I]. x> P [I]. y; <br/> double L = 0, r = 3.1415926/2; <br/> while (R-l> ESP) <br/>{< br/> double mid = (R + l)/2; <br/> double midmid = (R + mid)/2; <br/> double len1 = check (MID); <br/> double len2 = check (midmid); <br/> If (len1 <= len2) <br/> r = midmid; <br/> else l = mid; <br/>}< br/> double ans = check (R ); <br/> printf ("%. 2lf/N ", ANS * ans); <br/>}< br/> return 0; <br/>}