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轴的圆 ...
随机推荐
- splash
function main(splash, args) splash.images_enabled = false //不加载图片 assert(splash:go(args.url)) assert ...
- 20180821 Python学习笔记:如何获取当前程序路径
20180821 Python学习笔记:如何获取当前程序路径 启动的脚本的路径为:D:\WORK\gitbase\ShenzhenHouseInfoCrawler\main.py 当前脚本的路径为:D ...
- OpenCV3 for python3 学习笔记1
1.读/写图像文件 OpenCV的imread()函数和imwrite()函数能支持各种静态图像文件格式.不同系统支持的文件格式不一样,但都支持BMP格式,通常还应该支持PNG.JPEG和TIFF格式 ...
- TensorFlow实战Google深度学习框架10-12章学习笔记
目录 第10章 TensorFlow高层封装 第11章 TensorBoard可视化 第12章 TensorFlow计算加速 第10章 TensorFlow高层封装 目前比较流行的TensorFlow ...
- Libreoffice 各类文件转换的filtername
LIBREOFFICE_DOC_FAMILIES = [ "TextDocument", "WebDocument", "Spreadsheet&qu ...
- C#7.2——编写安全高效的C#代码 c# 中模拟一个模式匹配及匹配值抽取 走进 LINQ 的世界 移除Excel工作表密码保护小工具含C#源代码 腾讯QQ会员中心g_tk32算法【C#版】
C#7.2——编写安全高效的C#代码 2018-11-07 18:59 by 沉睡的木木夕, 123 阅读, 0 评论, 收藏, 编辑 原文地址:https://docs.microsoft.com/ ...
- Effective Java 第三版——70. 对可恢复条件使用检查异常,对编程错误使用运行时异常
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
- 企业和个人都需要的终极跨平台全端解决方案 UniApp
相信大家在平时开发过程中都会遇到这两类问题: 很多中小型企业要快速开发一个产品,这个产品至少需要覆盖平台范围为:ios.Android.web/H5.微信/支付宝小程序,那么需要的投入的人力成本.时间 ...
- mysql使用问题记录
Mysql Access denied for user 'root' ERROR 1045 (28000): Access denied for user 'root'@'localhost' (u ...
- git本地项目代码上传至码云远程仓库总结【转】
转载自 :https://blog.csdn.net/fox9916/article/details/78253714 git基本使用小结 之前公司的版本控制工具一直用的是svn,最近要改用git,之 ...