Radar Installation---(贪心)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 115873 | Accepted: 25574 |
Description
We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x-y coordinates.

Figure A Sample Input of Radar Installations
Input
The input is terminated by a line containing pair of zeros
Output
Sample Input
3 2
1 2
-3 1
2 1 1 2
0 2 0 0
Sample Output
Case 1: 2
Case 2: 1
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=;
#define INf 0x3f3f3f3f
struct node{
double l,r;
}point[maxn]; bool cmp(const node &a,const node &b){
return a.l<b.l;
} int main(){
int n,d;
int case1=;
while(~scanf("%d%d",&n,&d)&&n){
int flag=;
for(int i=; i<n; i++ ){
int x,y;
cin>>x>>y;
if(y>d){
flag=;
// break;
}
double p=sqrt((double)(d*d)-y*y);
point[i].l=x-p;
point[i].r=x+p;
}
printf("Case %d: ",++case1);
if(flag){
cout<<-<<endl;
continue;
}
sort(point,point+n,cmp);
int ans=;
node tmp=point[];
for( int i=; i<n; i++ ){
if(tmp.r>=point[i].r) tmp=point[i];
else if(tmp.r<point[i].l){
ans++;
tmp=point[i];
}
}
cout<<ans<<endl;
}
return ;
}
Radar Installation---(贪心)的更多相关文章
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- Radar Installation(贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56826 Accepted: 12 ...
- Radar Installation 贪心
Language: Default Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42 ...
- Radar Installation(贪心,可以转化为今年暑假不ac类型)
Radar Installation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- poj 1328 Radar Installation(贪心+快排)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)
Input The input consists of several test cases. The first line of each case contains two integers n ...
- POJ 1328 Radar Installation 贪心算法
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ1328 Radar Installation(贪心)
题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...
- poj1328 Radar Installation —— 贪心
题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...
- POJ 1328 Radar Installation 贪心题解
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...
随机推荐
- iOS链接库的冲突
最近在打包的时候,遇到一个坑.特此记录一下 起因是发现 Unity 5.4 版本,使用c#写的下载,下载速度无法突破 2M/s,同样的网络,后来横向对比使用原来 Cocos2d 开始的游戏,可以达到 ...
- 自定义spring参数注解 - 打破@RequestBody单体限制
本文主要描述怎样自定义类似@RequestBody这样的参数注解来打破@RequestBody的单体限制. 目录1 @RequestBody的单体限制2 自定义spring的参数注解3 编写sprin ...
- 不要使用Integer做HashMap的key,尤其在json序列化的时候
使用redisson cache来实现一个缓存功能,缓存省市县的名称,key是区域编码,integer,value是name.结果取的时候,怎么都取不出. Map<Integer, String ...
- ionic android升级检查
https://www.cnblogs.com/zxj159/p/4421578.html 坑: 放到cordova.file.DataDirectory下载异常? 只好cordova.file.ex ...
- 使用Træfɪk(traefik)来加速Qt在线更新
简述 在使用Qt的MaintenanceTool程序进行在线更新的时候遇到一个问题,就是访问download.qt.io实在太慢了,老是失败.所以想使用国内的镜像站来进行更新. 使用Qt的镜像站方法也 ...
- 认知:关于Android 调试的坑
要注意充电线和数据线的区别! 要注意充电线和数据线的区别! 要注意充电线和数据线的区别! 可以通过访问 :chrome://inspect/#devices 查看设备是否正常. 通常电脑也会有提示, ...
- mysql视图详解 mysql视图
目录 22.1. ALTER VIEW语法 22.2. CREATE VIEW语法 22.3. DROP VIEW语法 22.4. SHOW CREATE VIEW语法 本章讨论了下述主题: · ...
- ScreenToGif 使用教程
ScreenToGif 使用教程 ScreenToGif 是个强大的 Gif 录制/剪辑工具.其使用指南译文如下: 第一部分:录制 第二部分:编辑器 第三部分:主页.播放 第四部分:编辑.图像.过渡. ...
- 如何用cmd命令递归文件夹中的所有特定文件,拷贝到另一个文件夹中
现在有一个文件夹,里面有很多子文件夹,每个子文件夹中有很多不同类型的图片,现在想将其所有.png图片整理出来,一开始我是手动拷贝的,拷贝了几个图片后,突然想能不能让计算机来自动完成此项功能,经过一番尝 ...
- idea 配置 maven 项目
maven 项目 用模块引入进来 1.引入 pom.xml 2.如果不是web则要添加web支持 3.配置资源 类 和依赖 and 项目语言环境 5.配置 artifacts 部署 w ...