Codeforces 51c (three base stations)

Source: Internet
Author: User

[Description]

There are many houses on both sides of the expressway. Each house has its own coordinates. Now, given three base stations, each base station has a corresponding coverage radius D, now I want to make the base station cover all the houses. How should I build the base station and what is the minimum coverage radius?

[Solution ideas]

We can divide the coverage radius of the base station into two parts, and the left endpoint l of the two parts is 0, the right range endpoint R is C [N]-C [1], that is, the range occupied by all houses. In this way, you can calculate the base station radius. It is a little tricky to find the coordinates of the base station. You can see the following code.

AC code]

1 # include <iostream> 2 # include <cstdio> 3 # include <algorithm> 4 using namespace STD; 5 # define Max 2*100000 + 5 6 int C [Max]; 7 int ans [3]; 8 int N; 9 int fnext (int x) // calculate the next coordinate 10 {11 int L = 1, R = n + 1; 12 INT mid = (L + r)/2; 13 while (L <r) 14 {15 if (C [Mid] <= X) L = Mid + 1; 16 else r = mid; 17 mid = (L + r)/2; 18} 19 return mid; 20} 21 int OK (INT X) 22 {23 int z = 1; 24 for (INT I = 0; I <3; I ++) 25 {26 z = fnext (C [Z] + x ); // here is the next house on the right side of the house covered by a base station 27 ans [I] = z; // store Z to conveniently find the base station coordinates 28 If (z> = n + 1) return 1; 29} 30 return 0; 31} 32 int main () 33 {34 while (CIN> N) 35 {36 for (INT I = 1; I <n + 1; I ++) 37 {38 CIN> C [I]; 39} 40 sort (C + 1, C + 1 + n ); 41 int r = C [N]-C [1]; 42 int L = 0, mid = (L + r)/2; 43 while (L <R) 44 {45 if (OK (MID) r = mid; 46 else47 L = Mid + 1; 48 mid = (R + l)/2; 49} 50 OK (l); 51 double radious = L * 1.0/2.0; 52 double radar1 = (C [ans [0]-1] + C [1]) * 1.0/2.0; 53 double radar2 = (C [ans [1]-1] + C [ans [0]) * 1.0/2.0; 54 double radar3 = (C [ans [2]-1] + C [ans [1]) * 1.0/2.0; 55 printf ("%. 6f \ n ", radious); 56 printf (" %. 6f ", radar1); 57 printf (" %. 6f ", radar2); 58 printf (" %. 6f \ n ", radar3); 59} 60 return 0; 61 62}

 

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.