百練1328:Radar Installation

#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
int n, d;
struct Seg{
	double x1, x2;
	bool operator < (const Seg & s) const 
	{
		return x1 - s.x1 < -eps;
	}
};
Seg segs[1000];
int main()
{
	int t = 0;
	while((scanf("%d", &n) != EOF) && (scanf("%d", &d) != EOF)){
		
		if(n == 0) break;
		t++;
		bool bad = false;
		int i, j;
		for(i = 0; i < n; i++){
			
			int x, y;
			scanf("%d%d", &x, &y);
			
			if(y > d){
				bad = true;
				continue;
			}
			segs[i].x1 = x - sqrt(d*d - y*y);
			segs[i].x2 = x + sqrt(d*d - y*y);
 		}
 		if(bad){
 			printf("Case ");
 			printf("%d", t);
 			printf(": -1\n");
 			continue;
 		}
 		
 		sort(segs, segs + n);
 		int firstNoCovered = 0;
 		int total = 1;
 		for(i = 0; i < n; i++){
 			for(j = firstNoCovered; j < i; j++){
 				
 				if(segs[j].x2 < segs[i].x1){
 					total++;
 					firstNoCovered = i;
 					break;
 				}
 			}
 		}
 		
 		printf("Case ");
 		printf("%d", t);
 		printf(": ");
 		printf("%d\n", total);
	}
	
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章