题目大意:

  在X轴选择尽量少的点作为圆心,作半径为d的圆。使得这些圆能覆盖所有的点。

思路:

  把每个点都转化到X轴上。也就是可以覆盖这个点的圆心的位置的范围[a,b]。然后按照每个点对应的a从小到大排序。第一点需要特殊处理,我们赋值r=b。也就是使得第一个圆的圆心的横坐标尽量大。然后遍历剩下的点。对于i点,如果该点的ai大于r, 就需要增加一个圆,圆心为bi ;否则的话,把r更新为r与bi中小的值。

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int N = ;
struct node
{
double x,y;
double a,b;
}p[N];
bool cmp(node n1,node n2)
{
return n1.a<n2.a;
}
int main()
{
//freopen("test.txt","r",stdin);
int n,d,ca=;
while(scanf("%d%d",&n,&d)!=EOF&&n)
{
int i;
bool flag=;
for(i=;i<n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
if(p[i].y>d) flag=;
}
printf("Case %d: ",ca++);
if(flag) printf("-1\n");
else
{
for(i=;i<n;i++)
{
double x=p[i].x,y=p[i].y;
p[i].a=-sqrt(d*d-y*y)+x;
p[i].b=sqrt(d*d-y*y)+x;
}
sort(p,p+n,cmp);
double r=p[].b;
int ans=;
for(i=;i<n;i++)
{
if(p[i].a>r){
r=p[i].b;
ans++;
}
if(p[i].b<r) r=p[i].b;
}
printf("%d\n",ans);
}
}
return ;
}

poj1328 Radar Installation 区间贪心的更多相关文章

  1. POJ1328 Radar Installation 【贪心&#183;区间选点】

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 54593   Accepted: 12 ...

  2. POJ--1328 Radar Installation(贪心 排序)

    题目:Radar Installation 对于x轴上方的每个建筑 可以计算出x轴上一段区间可以包含这个点 所以就转化成 有多少个区间可以涵盖这所有的点 排序之后贪心一下就ok 用cin 好像一直t看 ...

  3. poj1328 Radar Installation(贪心 策略要选好)

    https://vjudge.net/problem/POJ-1328 贪心策略选错了恐怕就完了吧.. 一开始单纯地把island排序,然后想从左到右不断更新,其实这是错的...因为空中是个圆弧. 后 ...

  4. zoj1360/poj1328 Radar Installation(贪心)

    对每个岛屿,能覆盖它的雷达位于线段[x-sqrt(d*d-y*y),x+sqrt(d*d+y*y)],那么把每个岛屿对应的线段求出来后,其实就转化成了经典的贪心法案例:区间选点问题.数轴上有n个闭区间 ...

  5. [POJ1328]Radar Installation

    [POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one si ...

  6. POJ 1328 Radar Installation 【贪心 区间选点】

    解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的 ...

  7. poj 1328 Radar Installation【贪心区间选点】

    Radar Installation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

  8. poj 1328 Radar Installation 【贪心】【区间选点问题】

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 54798   Accepted: 12 ...

  9. POJ1328——Radar Installation

    Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...

随机推荐

  1. 消除input框的默认样式

    input, button, select, textarea { outline: none; -webkit-appearance: none; border-radius: 0; } outli ...

  2. 【codeforces 515C】Drazil and Factorial

    [题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的 ...

  3. 【郑轻邀请赛 I】这里是天堂!

    [题目链接]:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2135 [题意] [题解] 答案应该为C(n,a)∗C(m,b)/C(n+m,a+b) ...

  4. Android DynamicGrid:拖曳交换位置

     Android DynamicGrid:拖曳交换位置 Android DynamicGrid是一个第三方开源项目,DynamicGrid在github上的项目主页是:https://github ...

  5. Java 注解之总结

    注解是Spring和Mybatis框架所大量使用的技术,要想掌握框架相关技术,注解是必须要掌握的. 掌握注解的优势: 1.能够读懂别人写的代码,特别是框架相关的代码. 2.本来可能需要很多配置文件,需 ...

  6. mysql 源码 王恒 [mysql数据结构+mysql 执行计划]

    http://blog.chinaunix.net/uid/26896862/cid-156733-list-1.html http://www.it168.com/redian/wangheng/

  7. C语言实现的lisp解析器介绍

    近期.由于Perl而学习函数式编程, 再进一步学习lisp, 真是一学习就发现自己的渺小. 无意中找到了一个很easy的C语言版的, lisp解析器. 代码非常短, 却非常见功底, 涨姿势了. 附带还 ...

  8. HDU4882ZCC Loves Codefires(贪心)

    ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  9. 查询结果多个合并一个GROUP_CONCAT(EmployeeName)

    一个课程多个教师,查询结果单条显示,其中课程与教师关系是一一对应存入表中

  10. Project Euler:Problem 33 Digit cancelling fractions

    The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...