Three-point---POJ 3301 Texas trip

Source: Internet
Author: User

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&LT;&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.