Zoj 3368 trick or treat (second answer)

Source: Internet
Author: User

// The result is a binary answer. Note that the accuracy must be 1 E-5, and you do not need to use the same content as the sample. <br/> // The question is to find a point (x, 0) minimize the maximum distance between other points <br/> # include <iostream> <br/> # include <cmath> <br/> using namespace STD; <br/> struct coord <br/> {<br/> double X, Y; <br/>} A [50005]; <br/> double ans, l, r, mid, X; <br/> int ANSP, N; <br/> const double EPS = 1e-6; // precision setting <br/> void CAL (double mid) <br/> {<br/> ans = 0; <br/> for (INT I = 0; I <n; ++ I) // calculate the longest distance from the enumerated answer mid to all vertices <br/>{< br/> double Dis = SQRT (A [I]. x-mid) * (a [I]. x-mid) + A [I]. y * A [I]. y); <br/> If (DIS> ans) <br/>{< br/> ans = DIS; <br/> ANSP = I; <br/>}< br/> int main () <br/>{< br/> // freopen ("in.txt ", "r", stdin); <br/> while (scanf ("% d", & N) <br/>{< br/> ANSP = 0; // select any vertex. ANSP is the subscript of the vertex array <br/> L = 500000; <br/> r =-500000; <br/> for (INT I = 0; I <n; ++ I) <br/>{< br/> scanf ("% lf ", & A [I]. x, & A [I]. y); <br/> if (a [I]. x <L) L = A [I]. x; <br/> if (a [I]. x> r) r = A [I]. X // search for left and right boundary l, r <br/>}< br/> while (L <= r) <br/>{< br/> mid = (L + r)/2; <br/> double Dis = SQRT (A [ANSP]. x-mid) * (a [ANSP]. x-mid) + A [ANSP]. y * A [ANSP]. y); <br/> CAL (MID); // calculate with mid as the answer <br/> If (FABS (L-mid) <EPS) break; // if (a [ANSP]. x> mid) // The following three rows are the key to binary classification <br/> L = mid; <br/> elser = mid; <br/>}< br/> printf ("%. 9lf %. 9lf/N ", mid, 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.