对每个岛屿,能覆盖它的雷达位于线段[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. chattr

    chattr 功能:设置文件隐藏属性常用参数:+    增加某个特殊权限,其他原本存在的参数不动-     删除某个特殊权限,其他原本存在的参数不动=    设置一定,且仅有后面接的参数 i   文件 ...

  2. ASP.NET动态网站制作(19)-- C#(2)

    前言:C#的第二次课,依旧讲解C#的基础知识. 内容: 1.GC:垃圾回收机制,可以回收托管模块中的垃圾. 2.值类型和引用类型:  (1)值类型:所有的数值类型都是值类型,如int,byte,sho ...

  3. android shape的用法总结

    参考代码: <shape xmlns:android="http://schemas.android.com/apk/res/android" > <corner ...

  4. BZOJ 1602 [Usaco2008 Oct]牧场行走 dfs

    题意:id=1602">链接 方法:深搜暴力 解析: 这题刚看完还有点意思,没看范围前想了想树形DP,只是随便画个图看出来是没法DP的,所以去看范围. woc我没看错范围?果断n^2暴 ...

  5. Java Enum 比较用 == 还是 eques

    我是把枚举当作常量来使用的,枚举中还有两个自己的属性,关注到这个地方的朋友对枚举已经有了认识,这里就不再编写枚举的demo了,这里我直接说结果吧,在枚举中使用==和equals比较效果是一样的,查看源 ...

  6. http => https 升级

    准备证书 阿里云安全(云盾)-> CA证书服务,购买证书,个人测试的话可以使用免费的,期限1年. 购买证书后,把域名与证书进行绑定,提交审核,大概10分钟左右,正常情况下审核就可以通过.证书准备 ...

  7. UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256)

    今天使用MySQLdb往MySQL插入中文数据遇到一个异常: UnicodeEncodeError: 'latin-1' codec can't encode characters in positi ...

  8. React-Native在gitHub下载的Demo不能运行问题!!!

    1.目前找到的最可行的运行React-Native Demo的解决方案 请参考:http://blog.csdn.net/shubinniu/article/details/52873250 2.检查 ...

  9. CSS 布局实例系列(三)如何实现一个左右宽度固定,中间自适应的三列布局——也聊聊双飞翼

    今天聊聊一个经典的布局实例: 实现一个三列布局,其中左侧和右侧的部分宽度固定,中间部分宽度随浏览器宽度的变化而自适应变化 可能很多朋友已经笑了,这玩意儿通过双飞翼布局就能轻松实现.不过,还请容我在双飞 ...

  10. Asp.Net 5 Web Hook

    首先,然我们来看一下WebHooks是什么.WebHooks是一个协议.它们是HTTP回调技术.并且它们是"用户定义的HTTP回调".你和 (或) 您的应用程序在有什么事情发生时会 ...