码迷,mamicode.com
首页 > 其他好文 > 详细

Radar Installation

时间:2015-07-31 23:16:50      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:

#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
struct qj
{
 double l, r;
}b[1110];
bool cmp(qj a, qj b)
{
 if(a.r == b.r)
  return a.l > b.l;
 return a.r < b.r;
}
int main()
{
 double x, y;
 double d,temp;
 int  i, n, count, num=1;
 while(~scanf("%d %lf", &n, &d), n&&d)
 {
  for(i = 0; i < n; i ++)
  {
   scanf("%lf %lf", &x, &y);
   b[i].l = x - sqrt(d*d - y*y);//可求出卫星在X轴上的区间,根据勾股定理
   b[i].r = x + sqrt(d*d - y*y);
  }
  sort(b, b + n, cmp);
  count = 1;//记录卫星总数,现在右区间长度最小的地方安装一个卫星,这样卫星覆盖的范围才最广
  temp = b[0].r;
  for(i = 1; i < n; i ++)
  {
   if(b[i].l > temp)//看排名后的左区间是否在上一个卫星覆盖范围之内
   {
    temp = b[i].r;
    count++;
   }
  }
  printf("Case %d: %d\n", num++, count);
 }
 return 0;
}

Radar Installation

标签:

原文地址:http://www.cnblogs.com/digulove/p/4693238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!