Main topic:
Suppose there is an infinitely long coastline with N islands above the coastline. There are radars on the coastline, each radar can detect a circle with a radius of R, and the island can be detected by radar only when the distance between an island and the radar is less than or equal to R. gives the coordinates of all islands and the radius of the radar. The minimum number of radars required to make all islands detectable.
The ABCD in the figure is the location of the island. Assuming that the radius of the subject is 2 (conforming to the coordinate system), then the a point coordinate is () and so on.
In the title, record the coordinates of each point and add a new marker variable to mark whether it has been accessed.
Stores the intersection of the red circle and the x-axis in the graph. First, the sorting criteria are the order of the red circle and the left intersection of the x-axis.
, if the left intersection (J1 Point) of the B point circle (and so called) is to the left of the right intersection of the point Circle (E1), then the B point must be covered within the a point circle. Then, if the left intersection of the D-point circle (not shown in the figure) is right at the right intersection of the point circle (not marked), the D point is not in the A-point circle.
#include <iostream>#include <cmath>#include <algorithm>using namespace STD;structpoint{DoubleLeft, right;} dp[1050];intSumintCMP (point A, point B) {returnA.left<b.left;}voidSolveintN) {sort (DP, DP+N, CMP); sum=1;Double STD;STD=dp[0].right; for(intI=1; i<n; ++i) {if(dp[i].left>STD) {sum++;STD=dp[i].right; }Else if(dp[i].right<STD) {STD=dp[i].right; } }}intMain () {intN, R, X, y;intt=1; while(Cin>>n>>r&& (n+r!=0)) {intI, fail=0; for(i=0; i<n; i++) {Cin>>x>>y;if(Y>r) fail=1;Else{DoubleL=sqrt((Double) (R*r-y*y)); Dp[i].left=x-l; Dp[i].right=x+l; } }if(fail) {sum=-1;cout<<"Case"<<t++<<": "<<sum<<endl; }Else{solve (n);cout<<"Case"<<t++<<": "<<sum<<endl; } }}
POJ 1328 Radar Installation Greedy