poj 1328 Radar Installation

#include <cstdio>
#include <algorithm>
#include <cmath>
#define MAX_N    1100

using namespace std;

pair<int,int> point[MAX_N];
pair<double,double> arr[MAX_N];

//input
int n,d;
//answer
int ans;
int cnt = 1;

void solve(){
    ans = 1;
    //对点按左端点进行整理
    sort(arr,arr + n);
    //for(int i = 0;i < n;i++){
    //    printf("%lf %lf",arr[i].first,arr[i].second);
   // }

    double spos = arr[0].second;    //最左点的最右距离
    for(int i = 1;i < n; i++){
        if (arr[i].first - spos > 1e-5) {
            ans++;
            spos = arr[i].second;
        }else{
            if (arr[i].second - spos < 1e-5) //下个岛屿的最右坐标小于当前最右可被侦测坐标
            {
                spos= arr[i].second;
            }
        }
    }

}


int main(){
    //freopen("C:\in.txt","r",stdin);

    while(scanf("%d%d",&n,&d) != EOF){
        int ok = 1;
        if(!n && !d)
            break;
        for(int i = 0;i < n;i++){
            scanf("%d%d",&point[i].first,&point[i].second);

            if(point[i].second > d)  ok = 0;
        }

        //如果只有一个点
      //  if(n == 1) {printf("Case %d: 1\n",cnt++); continue;}
        //将坐标系上的点转为x轴上的区间

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

            double x = point[i].first,y = point[i].second;
            double len = sqrt((double)(d*d - y*y));
            arr[i].first =  x - len;
            arr[i].second = x + len;
        }

        if(ok == 0){
            printf("Case %d: -1\n",cnt++);
            continue;
        }else{
            solve();
            printf("Case %d: %d\n",cnt++,ans);
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值