HDOJ-三部曲-1002-Radar Installation
Radar Installation
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 60 Accepted Submission(s) : 11
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.

The input is terminated by a line containing pair of zeros
Case 2: 1
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
struct island
{
int x,y;
double rx,lx;
}; int cmp(const island &a,const island &b)
{
if(a.x<b.x)
return 1;
else
return 0;
} int main()
{
int cas=0,n,d;
while(cin>>n>>d&&n+d)
{
cas++;
island is[1001];
bool f=true;
for(int i=0;i<n;i++)
{
cin>>is[i].x>>is[i].y;
if(is[i].y>d)
f=false;
double t=sqrt(d*d-is[i].y*is[i].y);
is[i].lx=is[i].x-t;
is[i].rx=is[i].x+t;
}
if(!f)
{
cout<<"Case "<<cas<<": "<<-1<<endl;
}
else
{
sort(is,is+n,cmp);
/*for(int i=0;i<n;i++)
cout<<is[i].x<<' '<<is[i].rx<<' '<<is[i].lx<<endl;*/
double temp=is[0].rx;
int count=1;
for(int i=1;i<n;i++)
{
if(is[i].lx>temp)
{
count++;
temp=is[i].rx;
}
else if(is[i].rx<temp)
temp=is[i].rx;
}
cout<<"Case "<<cas<<": "<<count<<endl;
}
}
}
HDOJ-三部曲-1002-Radar Installation的更多相关文章
- hdoj Radar Installation
Problem Description Assume the coasting is an infinite straight line. Land is in one side of coastin ...
- [POJ1328]Radar Installation
[POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one si ...
- Radar Installation
Radar Installation 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/C 题目: De ...
- Radar Installation(贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56826 Accepted: 12 ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- Radar Installation 分类: POJ 2015-06-15 19:54 8人阅读 评论(0) 收藏
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 60120 Accepted: 13 ...
- poj 1328 Radar Installation(nyoj 287 Radar):贪心
点击打开链接 Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43490 Accep ...
- Poj 1328 / OpenJudge 1328 Radar Installation
1.Link: http://poj.org/problem?id=1328 http://bailian.openjudge.cn/practice/1328/ 2.Content: Radar I ...
- POJ1328——Radar Installation
Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...
- poj 1328 Radar Installation【贪心区间选点】
Radar Installation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
随机推荐
- Qt之QParallelAnimationGroup
简述 QParallelAnimationGroup类提供动画的并行组. QParallelAnimationGroup - 一个动画容器,当它启动的时候它里面的所有动画也启动,即:并行运行所有动画, ...
- WPF:行列显示
新建显示病人信息控件PatientElement Add-->NewItem-->WPF-->UserControl(WPF),名称:PatientElement.xmal < ...
- 初始maven
Apache Maven 是一个软件项目管理和综合工具.基于项目对象模型 (POM) 的概念,Maven 可以管理一个项目的生成. 报告和文档从一块中央的信息.在JavaEE中,我们可以使用Maven ...
- oracle第一章
1.oracle对比sqlserver oracle sqlserver 数据文件.dbf 数据文件.mdf 控制文件.ctl 日志文件.log 日志文件.log 2.内置用户 1.sys ...
- 个人介绍和GitHub
基本信息: 姓名:陈晖 学号:1413042068 班级:网工143 兴趣爱好:看小说,打游戏,听古风音乐,打羽毛球,骑行等 个人编程能力不高,写的代码都是作业…… GitHub注册流程: 对于Git ...
- Java--常用类summary
/* 2:API的概述(了解) (1)应用程序编程接口. (2)就是JDK提供给我们的一些提高编程效率的java类. 3:Object类(掌握) (1)Object是类层次结构的根类,所有的类都直接或 ...
- easyui numberbox不可编辑
今天又遇到了给easyui中numberbox设置不可编辑的功能,在(http://www.jeasyuicn.com/api/docTtml/index.htm)API中找到了一个方法:
- display和visibility的区别
一.display和visibility的相同与不同点 1.相同点:display和visibility都有讲元素隐藏的意思 2.不同点:display是元素隐藏,隐藏的元素不占文档流 而visibi ...
- 在Ios里UIWebView参入js
//修改图片大小适应webView宽高度 [webView stringByEvaluatingJavaScriptFromString: @"var sc ...
- bind,unbing,on,live,delegate绑定和解绑事件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/T ...