POJ1328

就是找至少需要多少个圆可以把所有点覆盖完,圆心坐标必须在x轴上,所以当一个海岛坐标的y值大于d时,可以直接打印-1,这种情况不能覆盖完所有的点;其它情况,就是找出海岛对应的在x轴上的坐标点,然后再进行判断即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
#include<set>
#include<vector>
using namespace std;
const int MAX=1005;
struct ARR
{
	double l,r;
}arr[MAX];
int comp(ARR a,ARR b)
{
	return a.l==b.l?a.r<b.r:a.l<b.l;
}
int main()
{
	int t=1,n,d;
while(scanf("%d%d",&n,&d)&&n) 
{
		bool flag = true;
		for(int i = 0; i < n; i++)
		 {
			int a,b;
			scanf("%d%d",&a,&b);
			if(b>d) 
				 flag=false;
			double temp= sqrt(d * d - b * b);
			arr[i].l = a - temp; arr[i].r = a + temp;
			
		}
	   if(flag==false)
	    	{
	    		cout << "Case " << t++ << ": -1" << endl ;
	    		continue;
	    	}
		sort(arr, arr+n,comp);
		int ans = 1;
		double k= arr[0].r;
		for(int i=1;i<n;i++) 
			{
				if(k > arr[i].r)
					k = arr[i].r;
				else if(k<arr[i].l)
				 {
					ans++;
					k=arr[i].r;
				}
			}
		cout << "Case " << t++ << ": " << ans << endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值