Poj 3301 Texas trip

Source: Internet
Author: User

Question:

Points are given in the two-dimensional coordinate system, and the area of the smallest square can be covered (the side of a square is not necessarily a parallel coordinate axis)


Solution:

For a point, if the coordinate axis rotates degrees A (in radians), then x' = x * Cos (a)-y * sin (); y' = y * Cos (A) + x * sin ();


For the three-point angle, the square area is a single-peak function in [0, Pi ]. Has a minimum value.


The following code is used:

 

#include <set>#include <map>#include <queue>#include <math.h>#include <vector>#include <string>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>#define eps 1e-8#define pi acos(-1.0)#define inf 107374182#define inf64 1152921504606846976#define lc l,m,tr<<1#define rc m + 1,r,tr<<1|1#define iabs(x)  ((x) > 0 ? (x) : -(x))#define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (SIZE))#define clearall(A, X) memset(A, X, sizeof(A))#define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE))#define memcopyall(A, X) memcpy(A , X ,sizeof(X))#define max( x, y )  ( ((x) > (y)) ? (x) : (y) )#define min( x, y )  ( ((x) < (y)) ? (x) : (y) )using namespace std;struct node{    double x,y;}point[305];int n;double does(double a){    double maxx=-10000000,maxy=-100000000,minx=100000000,miny=100000000,tx,ty;    for(int i=0;i<n;i++)    {        tx=point[i].x*cos(a)-point[i].y*sin(a);        ty=point[i].y*cos(a)+point[i].x*sin(a);        maxx=max(maxx,tx);        maxy=max(maxy,ty);        minx=min(minx,tx);        miny=min(miny,ty);    }    return max(maxx-minx,maxy-miny);}int main(){    int T;    double l,r,lmid,rmid,ans1,ans2;    scanf("%d",&T);    while(T--)    {        scanf("%d",&n);        for(int i=0;i<n;i++)        {            scanf("%lf%lf",&point[i].x,&point[i].y);        }        l=0.0;        r=pi;        while(r-l>eps)        {            lmid=(l+r)/2;            rmid=(lmid+r)/2;            ans1=does(lmid);            ans2=does(rmid);            if(ans1<=ans2)r=rmid;            else l=lmid;        }        printf("%.2lf\n",ans1*ans1);    }    return 0;}

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.