poj1328

#include<stdio.h>

#include<stdlib.h>

#include<math.h>

struct g{

	double l,r;

}point[1005];

int cmp(const void *a,const void *b)

{

	return (*(struct g *)a).l>(*(struct g *)b).l?1:-1;

}

int main(){

	int i,n,tcase=1,ans;

	double a,b;

	bool flag;

	double dis,temp;

	scanf("%d%lf",&n,&dis);

	while (n!=0||dis!=0){

		flag=true;

		for(i=0;i<n;i++){

			scanf("%lf%lf",&a,&b);

			if(b>dis)

				flag=false;

			point[i].l=a-sqrt(dis*dis-b*b);

			point[i].r=a+sqrt(dis*dis-b*b);

		}

		printf("Case %d: ",tcase++);

		if(flag==false){

			printf("-1\n");

		}else{

		qsort(point,n,sizeof(point[0]),cmp);

		ans=1;

		temp=point[0].r;

		for(i=1;i<n;i++){

			if(temp<point[i].l){

				ans++;

				temp=point[i].r;

			}

			else

				if(temp>=point[i].l&&temp<point[i].r){

					continue;

				}

				else

					if(temp>point[i].r){

						temp=point[i].r;

					}

		}

		printf("%d\n",ans);

		}

		scanf("%d%lf",&n,&dis);

	}

	return 0;

}

  

你可能感兴趣的:(poj)