Texas Trip
problem ' s Link:
http://poj.org/problem?id=3301
Mean:
Given n (n <= 30) points, find the area of the smallest square containing the points.
Analyse:
The first thing to be sure is that the angle of rotation is between 0-180 degrees, and more than 180 degrees is the same as the previous one.
After the axis rotates, the coordinate transformation is:
X ' = x * cosa-y *= y * cosa + x * SINA;
Time Complexity:o (n)
Source Code:
//Memory Time//1347K 0MS//by:crazyacking//2015-03-31-22.18#include <map>#include<queue>#include<stack>#include<cmath>#include<cstdio>#include<vector>#include<string>#include<cstdlib>#include<cstring>#include<climits>#include<iostream>#include<algorithm>#defineMAXN 1000010#defineLL Long Longusing namespacestd;#defineEPS 1e-12#defineINF (1<<25)Doubleppx[ +],ppy[ +];intN;DoubleCal (Doublea) { Doublexmin=inf*1.0, ymin=inf*1.0, xmax=-inf*1.0, ymax=-inf*1.0; for(intI=1; i<=n;i++) { DoubleX1=ppx[i]*cos (a)-ppy[i]*sin (a); DoubleY1=ppx[i]*sin (a) +ppy[i]*cos (a); if(x1>xmax) Xmax=X1; if(x1<xMin) XMin=X1; if(y1>yMax) YMax=Y1; if(y1<ymin) ymin=Y1; } if(xmax-xmin<ymax-ymin)returnymax-ymin; Else returnxmax-xMin;}intMain () {intT; intx, y; scanf ("%d",&t); while(t--) {scanf ("%d",&N); for(intI=1; i<=n;i++) {scanf ("%d%d",&x,&y); Ppx[i]=x+500.0; Ppy[i]=y+500.0; } Doublele=0, ri=Pi,mid,mmid; DoubleMid_va,mmid_va; while(le+eps<=RI) {Mid= (Le+ri)/2; Mmid= (Mid+ri)/2; Mid_va=Cal (mid); Mmid_va=Cal (Mmid); if(mid_va<Mmid_va) Ri=Mmid; Elsele=mid; } printf ("%.2lf\n", Cal (LE) *Cal (le)); } return 0;}
View Code
Three-point---POJ 3301 Texas trip