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) ...
随机推荐
- 经典排序算法---冒泡排序(Bubble Sort)
原理是临近的数字两两进行比较,按照从小到大或者从大到小的顺序进行交换, 这样一趟过去后,最大或最小的数字被交换到了最后一位,然后再从头开始进行两两比较交换,直到倒数第二位时结束 void Bubble ...
- java多线程的常用方法(以及注意事项)
/* * 线程的常用方法 * 1.start(); * 2.run(); * 3.sleep(int millsecond); * 4.isAlive(); -->判断线程是否还在运行 * 5. ...
- Snappy压缩
Snappy压缩时,碰到不能解压问题,所用服务器Tomcat8.经验证,降低Tomcat版本为7,才可正常解压文件. 若碰到偶尔不能解压的问题,试着换个浏览器试试.
- spring mvc表单自动装入实体对象
<form action="/springmvc1/user/add" method="post"> id: <input type=&quo ...
- L1 - 闭包和原型链
先来一炮尝尝: var i = 10; function myFunc(){ var i = 20; function innerFunc(){ alert(i); } return innerFun ...
- S1 :数组迭代方法
ECMAScript 5 还新增了两个归并数组的方法:reduce()和reduceRight().这两个方法都会迭代数组的所有项,然后构建一个最终返回的值.其中,reduce()方法从数组的第一项开 ...
- node.js安装及grunt插件,如何进行脚本压缩
http://gruntjs.com/pluginshttp://gruntjs.com/getting-startedhttp://gruntjs.com/configuring-tasks#glo ...
- EditorLineEnds.ttr 错误问题
安装 Windows Write Live,在线安装,会先安装一个什么补丁,中途提示失败. 运行Delphi2007,第一次成功,第二次就是 EditorLineEnds.ttr文件错误. http: ...
- PS通道抠图总结
看了那么多的通道抠图,总结几点就是 1.你要有很强的色彩意识,怎样调节对比色等才能增加主体和背景的色差 2.流水步骤 Ctrl+J复制背景图层 调整主体和背景的色差 进入通道面板,找到主体和背景对比最 ...
- 查看UI调试界面利器 revealapp
官网 http://revealapp.com 做iOS的开发,UI是非常非常重要的一环.调试时我们一般用模拟器,提交前用真机做测试.用模拟器来调试UI效果虽然快捷方便,但有时仍然希望有更强大的工具来 ...