poj 1328 - nyoj278 radar

#include <stdio.h>
#include  <string.h>
#include <math.h>
#include <algorithm>

using namespace std;
const int MAX = 1000;

typedef struct {
	double x;
	double y;
	double left;
	double right;
} Ir;
Ir lo[MAX];


int main(void) {
	//FILE *fp;
	int n;
	double d;
	int flag, Case = 1;


	//fp = fopen("1.txt", "r");
	//fscanf(fp, "%d%d", &n, &d);
	scanf("%d %lf", &n, &d);
	for(; n && d;scanf("%d %lf", &n, &d)) {
		flag = 0; //假设数据无误
		for(int i=0; i<n; i++) {
			scanf("%lf %lf", &lo[i].x, &lo[i].y);
			int yt = lo[i].y;
			lo[i].right = lo[i].x + sqrt(d*d - yt*yt);
			lo[i].left = lo[i].x - sqrt(d*d - yt*yt);
			if(lo[i].y > d || d < 0 || lo[i].y < 0)
				flag = 1;
		}
		
		//异常退出 
		if(flag) {
			printf("Case %d: -1\n", Case++);
			continue;
		}
		
		//排序 
		for(int i=0; i<n-1; i++) {
			for(int j=0; j<n-i-1; j++) {
				if(lo[j].x > lo[j+1].x) {
					Ir temp = lo[j];
					lo[j] = lo[j+1];
					lo[j+1] = temp;
				}
			}
		}

		//放置雷达 
		double first = lo[0].right;
		int number = 1;
		for(int i=1; i<n; i++) {
			if(lo[i].right < first)
				first = lo[i].right;
			else if(lo[i].left > first) {
				number++;
				first = lo[i].right;
			}	
		}
		printf("Case %d: %d\n", Case++, number);
	}


	return 0;
}


你可能感兴趣的:(poj 1328 - nyoj278 radar)