poj1328 radar installation


//以各岛为圆心做半径为b的圆,记录下每个圆与x坐标轴的左右交点,然后进行贪心选择。 本质上每一个圆的左右交点连成的线段就是一个雷达放置的位置范围 
#include<iostream>
#include<math.h>
#include<algorithm> 
using namespace std;
struct point{
	double left;//左交点 
	double right;//右交点 
}a[100],temp; 
int cmp(point a,point b)
{
	return a.left<b.left?1:0;//按照左交点的坐标从小到大排序 
}
int main()
{	
	int n;
	double r;
	while(cin>>n>>r&&n&&r)
	{
		bool flag=false;
		for(int i=0;i<n;i++)
		{
			double an,bn;//岛的坐标 
			cin>>an>>bn;
			if(fabs(bn)>r)//说明无论雷达在哪里都不能覆盖岛
				flag=true;
			else
			{
				a[i].left = an * 1.0 - sqrt(r * r - bn * bn);  
         	   a[i].right = an * 1.0 + sqrt(r * r - bn * bn);
			 }
		}
		
		if (flag)  
  	 	{  
   	 	 cout << -1 << endl;  
   		}  
   		else
        { 
    		int count = 1;  
      		sort(a, a + n,cmp);  //按照左交点从小到大排序 
       		temp = a[0];  
       		for (int i = 1; i < n; i++)  
      		{  
          	  if (a[i].left > temp.right)  
          	  {  
                count++;  
                temp = a[i];  
              }  
   
     		 }  
          cout << count << endl; 
    	} 
	}

	return 0;
	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值