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轴的圆 ...
随机推荐
- .Net转Java.06.字符串的split的区别
在Java遇到了将类似“1|2|3|4”的字符串分隔为数组的功能 这种问题能难倒有着十多年开发经验的的.NET码农? // Java代码 String s="1|2|3"; Str ...
- golang gob 有什么优势? gob/protobuf/json/xml 效率对比,benchmark 压力测试
TODO 待研究: https://blog.csdn.net/love_se/article/details/7941876 https://blog.csdn.net/wangshubo1989/ ...
- CentOS7+Hadoop2.7.2(HA高可用+Federation联邦)+Hive1.2.1+Spark2.1.0 完全分布式集群安装
1 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.9.1 2.9.2 2.9.2.1 2.9.2.2 2.9.3 2.9.3.1 2.9.3.2 2.9.3.3 2. ...
- SSE图像算法优化系列六:OpenCv关于灰度积分图的SSE代码学习和改进。
最近一直沉迷于SSE方面的优化,实在找不到想学习的参考资料了,就拿个笔记本放在腿上翻翻OpenCv的源代码,无意中看到了OpenCv中关于积分图的代码,仔细研习了一番,觉得OpenCv对SSE的灵活运 ...
- 什么是rpc
远程过程调用协议RPC(Remote Procedure Call)—远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.RPC协议假定某些传输协议的存在,如TC ...
- maven scope使用和理解
在Maven的依赖管理中,经常会用到依赖的scope设置.这里整理下各种scope的使用场景和说明,以及在使用中的实践心得. scope的使用场景和说明 1.compile 编译范围,默认scope, ...
- RapidJson 的使用
rapidjson为了最大化性能,大量使用了浅拷贝,使用之前一定要了解清楚.如果采用了浅拷贝,特别要注意局部对象的使用,以防止对象已被析构了,却还在被使用. rapidjson使用注意点: 1.对不存 ...
- vue移动端flexible.js结合Muse-ui使用和vux的小坑
因为公司有个项目有webapp的需求,在前期准备的期间考虑过使用ionic,毕竟该项目web端的框架使用的是Angular,项目组的人也都比较熟悉,但是我们毕竟只是做个移动的网页,不想用ionic那么 ...
- mysql(5.7)配置文件示例
# For advice on how to change settings please see# http://dev.mysql.com/doc/refman/5.6/en/server-con ...
- dom4j 简单使用
1,需要用到dom4j的jar包.为了打开xml方便,设计一个简单的封装类. package cn.com.gtmc.glaf2.util; import java.io.File; import j ...