对每个岛屿,能覆盖它的雷达位于线段[x-sqrt(d*d-y*y),x+sqrt(d*d+y*y)],那么把每个岛屿对应的线段求出来后,其实就转化成了经典的贪心法案例:区间选点问题。数轴上有n个闭区间[ai,bi],取尽量少的点,使得每个区间内都至少有一个点。选法是:把区间按右端点从小到大排序(右端点相同时按左端点从大到小),然后每个没选的区间选最右边的一个点即可。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<deque>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const double eps=1e-;
const int INF=;
const int maxn=+; int n,cas=;
double d,x,y;
struct Line
{
double l,r;
bool used;
Line(double ll=,double rr=,bool uu=false):l(ll),r(rr),used(uu) {}
Line(const Line& C)
{
l=C.l;
r=C.r;
used=C.used;
}
bool operator < (const Line& B) const
{
if(r!=B.r)
return r<B.r;
else
return l>B.l;
}
} a[maxn]; int main()
{
//freopen("in2.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d%lf",&n,&d)==)
{
if(n==&&d==) break;
printf("Case %d: ",cas++);
int ans=;
for(int i=; i<n; i++)
{
scanf("%lf%lf",&x,&y);
if(y>d)
{
ans=-;
break;
}
a[i].l=x-sqrt(d*d-y*y);
a[i].r=x+sqrt(d*d-y*y);
//cout<<a[i].l<<' '<<a[i].r<<endl;
a[i].used=false;
}
if(ans==-)
{
printf("-1\n");
}
else
{
sort(a,a+n);
for(int i=; i<n; i++)
{
//cout<<a[i].l<<' '<<a[i].r<<endl;
if(a[i].used==false)
{
a[i].used=true;
ans++;
for(int j=i+; j<n; j++)
{
if(a[j].l<=a[i].r)
{
a[j].used=true;
}
else break;
}
}
}
printf("%d\n",ans);
}
}
//fclose(stdin);
//fclose(stdout);
return ;
}

zoj1360/poj1328 Radar Installation(贪心)的更多相关文章

  1. POJ1328 Radar Installation(贪心)

    题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...

  2. poj1328 Radar Installation —— 贪心

    题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...

  3. ZOJ-1360 || POJ-1328——Radar Installation

    ZOJ地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=360 POJ地址:http://poj.org/problem?id ...

  4. [POJ1328]Radar Installation

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

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

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

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

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

  7. POJ 1328 Radar Installation 贪心 A

    POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...

  8. POJ1328——Radar Installation

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

  9. POJ1328 Radar Installation 解题报告

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

随机推荐

  1. mysql主从实验

    实验一: 服务器A与服务器B是主从关系,关联的库有test1,.test2库,主从一直运行正常,此时由于业务的需求,需再增加test3库,并让其仍然维持主从关系,应该怎么做? 步骤一: 修改从库服务器 ...

  2. Pairs of Integers

    Pairs of Integers You are to find all pairs of integers such that their sum is equal to the given in ...

  3. D-hdu 1465 不容易系列之一(递推)

    hdu 1465 不容易系列之一(错排) 不容易系列之一 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  4. 广告 竞价排名 import Levenshtein as Le seqratio_res = Le.seqratio(chk_name_lsit, cmp_)

    pip install python-Levenshtein from openpyxl import Workbook import xlrd import time import Levensht ...

  5. office2013安装/激活

    ed2k://|file|cn_office_professional_plus_2013_x64_dvd_1134006.iso|914106368|E5FBAE9EE9CB35D5E777EA78 ...

  6. 【python】-- 函数、无参/有参参数、全局变量/局部变量

    函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.你已经知道Python提供了许多内建函数,比如print().但你也可以自己创建函 ...

  7. 洛谷2704 [NOI2001]炮兵阵地

    题目戳这里 Solution 状压DP很好的入门题,用熟练位运算貌似也没那么难. 首先分析一下题目: 看见n=100,m=10,立马就想到了状压,看起来也像DP,所以我们还是采用行号为阶段的状压DP. ...

  8. 几则js表达式

    过滤大段文本里的标签.标签格式 <...>,如下匹配标签然后替换成空 校验邮箱是否符合: 去掉行首行尾空格: 检测字符串是否包含中文:(utf8编码)

  9. 15.Django添加一个功能模块的步骤(和SpringMVC类比)

    这里介绍如何在Django里新建一个模块,这个例子还是最简单的例子 通过浏览器访问 http://localhost:8000/hello/然后返回一个欢迎页 我是做java web出身的,这里用py ...

  10. 读取ByteBuffer有效的数据

    转:https://zhidao.baidu.com/question/427134449349230532.html说道 ByteBuffer的缓冲区,就需要知道缓冲区的的三个状态1)capacit ...