博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ1328 Radar Installation 【贪心·区间选点】
阅读量:6347 次
发布时间:2019-06-22

本文共 2748 字,大约阅读时间需要 9 分钟。

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

Description

Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d. 
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 consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n lines each containing two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases. 
The input is terminated by a line containing pair of zeros 

Output

For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. "-1" installation means no solution for that case.

Sample Input

3 21 2-3 12 11 20 20 0

Sample Output

Case 1: 2Case 2: 1

Source

#include 
#include
#include
#include
#define maxn 1010using namespace std;struct Node { double u, v; friend bool operator<(const Node& a, const Node& b) { return a.u < b.u; }} E[maxn];int N, D;int main() { int i, ok, id, ans, cas = 1; double x, y, d, flag; while(scanf("%d%d", &N, &D), N) { printf("Case %d: ", cas++); ok = 1; id = 0; for(i = 0; i < N; ++i) { scanf("%lf%lf", &x, &y); if(y > D) ok = 0; if(!ok) continue; d = sqrt(D * D - y * y); E[id].u = x - d; E[id++].v = x + d; } if(!ok) { printf("-1\n"); continue; } sort(E, E + id); flag = E[0].v; ans = 1; for(i = 1; i < N; ++i) { if(E[i].u <= flag) { if(E[i].v <= flag) flag = E[i].v; continue; } ++ans; flag = E[i].v; } printf("%d\n", ans); } return 0;}

转载于:https://www.cnblogs.com/yutingliuyl/p/6758699.html

你可能感兴趣的文章
linux下SSH远程连接服务慢解决方案
查看>>
利用mic visual studio 2010 编译器执行wincap获取网络适配器的代码
查看>>
HTML
查看>>
CENTOS7下编译安装PHP-5.4以及配置phpMyAdmin
查看>>
Ant+Jmeter+Jenkins 环境配置初探
查看>>
javascript之数组的6种去重方法
查看>>
爱创课堂每日一题九十四天- 对WEB标准以及W3C的理解与认识?
查看>>
磁盘显示无法访问拒绝访问,里面的资料怎样找到
查看>>
Java之品优购课程讲义_day07(5)
查看>>
Java的新项目学成在线笔记-day3(八)
查看>>
Windows 下 Python 3.6 下安装 TensorFlow (屡败屡战)
查看>>
php中base64_decode与base64_encode加密解密函数
查看>>
Windows常用知识总结
查看>>
华为交换机hybrid配置小实验
查看>>
单位网络布线中需要注意的几个问题及心得
查看>>
Hanlp分词之CRF中文词法分析详解
查看>>
苹果宣布开源 FoundationDB 数据库
查看>>
关于CmsEasy数据库配置文件修改路径说明
查看>>
openStack 主机流量计运行状态 随笔记录
查看>>
Niushop针对商城难推广提出6大方法,一切如此简单!
查看>>