#include <stdio.h>
#include <math.h>
#define MAX 1001
int islands;
int radius;
int x[MAX];
int y[MAX];
double left[MAX];
double right[MAX];
int radars;
double radarX;
int partition(int left, int right){
int pivotValueX = x[left];
int pivotValueY = y[left];
while (left < right){
while (left < right && x[right] >= pivotValueX){
right--;
}
x[left] = x[right];
y[left] = y[right];
while (left < right && x[left] <= pivotValueX){
left++;
}
x[right] = x[left];
y[right] = y[left];
}
x[left] = pivotValueX;
y[left] = pivotValueY;
return left;
}
void quickSort(int left, int right){
if (left == right){
return;
}
int pivot = partition(left, right);
partition(left, pivot - 1);
partition(pivot + 1, right);
}
int main()
{
int caseNum = 0;
while (scanf("%d %d", &islands, &radius)!= EOF){
if (islands == 0 && radius == 0){
return 0;
}
int noSolution = 0;
int island;
for (island = 0; island < islands; island++){
scanf("%d %d", &x[island], &y[island]);
if (y[island] > radius){
noSolution = 1;
}
}
if (noSolution == 1 || radius <= 0){
printf("Case %d: -1\n", ++caseNum);
continue;
}
int round;
for (round = 1; round < islands; round++){
int island;
for (island = 0; island < islands - round; island++){
if (x[island] > x[island + 1]){
int temp = x[island];
x[island] = x[island + 1];
x[island + 1] = temp;
temp = y[island];
y[island] = y[island + 1];
y[island + 1] = temp;
}
}
}
for (island = 0; island < islands; island++){
double temp = sqrt((double)(radius * radius - y[island] * y[island]));
left[island] = x[island] - temp;
right[island] = x[island] + temp;
}
radars = 1;
radarX = right[0];
for (island = 1; island < islands; island++){
if (left[island] > radarX){
radars++;
radarX = right[island];
} else if (right[island] < radarX){
radarX = right[island];
}
}
printf("Case %d: %d\n", ++caseNum, radars);
}
return 0;
}
POJ 1382 Cover The Island
最新推荐文章于 2021-01-25 15:35:14 发布