A: There is a coastline. There is a sea above the coastline. There are some islands in the sea. The locations of these islands are known. There are radars on the coastline, and the radar coverage radius is known, ask how many radars are needed to cover all the islands.
Idea: the coordinates of each island are known, and the radar radius is used as the radius to draw a circle. There are two intersections with the X axis. That is to say, to cover the island, the radar's location range is the two intersections. Therefore, it is converted into a coverage range.
Code:
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <algorithm>
# Include <cmath>
# Include <string. h>
Using namespace std;
Const int n= 1010;
Struct point {
Int x, y;
} Pp [N];
Struct line {
Double sp, ep;
} Ll [N];
Bool cmp (line a, line B ){
If (a. ep = B. ep)
Return a. sp <B. sp;
Return a. ep <B. ep;
} Www.2cto.com
Int main (){
// Freopen ("1.txt"," r ", stdin );
Int n, len, ca = 1;
While (scanf ("% d", & n, & len )){
Bool islen = false;
If (len <0 ){
Islen = true;
}
If (n + len = 0 & len> = 0)
Break;
Bool flag = false;
For (int I = 0; I <n; ++ I ){
Scanf ("% d", & pp [I]. x, & pp [I]. y );
If (pp [I]. y> len)
Flag = true;
Double vx = sqrt (len * len-pp [I]. y * pp [I]. y) * 1.0 );
Ll [I]. sp = pp [I]. x-vx;
Ll [I]. ep = pp [I]. x + vx;
}
If (flag | islen ){
Printf ("Case % d:-1 \ n", ca ++ );
Continue;
}
Sort (ll, ll + n, cmp );
Bool isuse [N];
Memset (isuse, false, sizeof (isuse ));
Int ans = 0;
For (int I = 0; I <n; ++ I ){
If (isuse [I])
Continue;
Isuse [I] = true;
Ans ++;
For (int j = I + 1; j <n; ++ j ){
If (isuse [j])
Continue;
If (ll [j]. sp <= ll [I]. ep ){
Isuse [j] = true;
}
}
}
Printf ("Case % d: % d \ n", ca ++, ans );
}
Return 0;
}