poj-1328

题意:在一个平面坐标轴上,第一第二象限为海洋,第三第四象限为陆地,x轴上可以放雷达,已知岛屿的坐标求最少可以放多少个雷达。(雷达扫描范围固定)

题解:以岛屿为中心扫描范围为半径算出于x轴的交点,以靠左边的坐标为基准从小到大排序。设一个标记为第一个岛屿的右边,与之后的对比判断。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <math.h>
#include <stdlib.h>
#include <time.h>

#define ll long long
#define maxn 2010

using namespace std;

struct node{
	double l,r;
}a[1010];

bool cmp(node a,node b){
	if(a.l==b.l){
		return a.r>b.r;
	}else{
		return a.l<b.l;
	}
}

int main(){
	int n,d,x,y,cas = 1;
	while(cin>>n>>d&&(n+d)){
		int judge = 1;
		for(int i = 0 ; i < n ; i++){
			scanf("%d %d",&x,&y);
			if(y>d){
				judge = 0;
				continue;
			}
			a[i].l = 1.0*x - sqrt(1.0*d*d-1.0*y*y);
			a[i].r = 1.0*x + sqrt(1.0*d*d-1.0*y*y);
		}
		if(!judge){
			cout<<"Case "<<cas++<<": -1"<<endl;
			continue;
		}
		sort(a,a+n,cmp);
		double mark = a[0].r;
		int ans = 0;
		for(int i = 1 ; i < n ; i++){
			if(a[i].l>mark){
				mark = a[i].r;
				ans++;
			}else if(a[i].r<mark){
				mark = a[i].r;
			}
		}
		cout<<"Case "<<cas++<<": "<<++ans<<endl;
	}
} 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值