Poj3301 -- Texas trip

Source: Internet
Author: User

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/>}

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.