poj 1328 Radar Installation

来源:互联网 发布:验证域名所有权的方法 编辑:程序博客网 时间:2024/06/05 07:17
#include <cstdio>#include <algorithm>#include <cmath>#define MAX_N    1100using namespace std;pair<int,int> point[MAX_N];pair<double,double> arr[MAX_N];//inputint n,d;//answerint 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;}

0 0
原创粉丝点击