题目:http://poj.org/problem?id=3301
View Code
#include <cstdio> #include <cmath> #include <cstring> #include <algorithm> using namespace std; const double M = 1e99; const double pi = acos(-1.0); const double eps = 1e-8; struct node { double x, y; void get(){ scanf("%lf%lf", &x, &y); } }p[40]; int T, n; double len(double f){ double l=M, r=-M, d=M, u=-M, x, y; for (int i=0; i<n; i++){ x = cos(f)*p[i].x - sin(f)*p[i].y; y = sin(f)*p[i].x + cos(f)*p[i].y; l = min(l, x); r = max(r, x); d = min(d, y); u = max(u, y); } return max(r-l, u-d); } void solve(){ double mid, midmid, lef, rig; for (lef=0, rig=pi/2; lef+eps<=rig;){ mid = (lef + rig) / 2; midmid = (mid + rig) / 2; if (len(mid)>=len(midmid))lef=mid; else rig=midmid; } printf("%.2f\n", len(lef)*len(lef)); } int main() { //freopen("D:/10101441/a.txt", "r", stdin); scanf("%d", &T); while (T--){ scanf("%d", &n); for (int i=0; i<n; i++)p[i].get(); solve(); } return 0; }