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) ...
随机推荐
- HTML5自学笔记[ 8 ]历史管理
触发历史管理的三种方法: 跳转页面 改变hash值 pushState(在服务器环境下运行) 用hash值来触发历史管理: <!doctype html> <html lang=&q ...
- 2016年31款轻量高效的开源JavaScript插件和库
目前有很多网站设计师和开发者喜欢使用由JavaScript开发的插件和库,但同时面临一个苦恼的问题:它们中的大多数实在是太累赘而且常常降低网站的性能.其实,其中也有不少轻量级的插件和库,它们不仅轻巧有 ...
- 20145236 《Java程序设计》实验五实验报告
20145236 实验五 Java网络编程 实验内容 1.运行TCP代码,结对进行,一人服务器,一人客户端: 2.利用加解密代码包,编译运行代码,一人加密,一人解密: 3.集成代码,一人加密后通过TC ...
- Java多线程-新特征-锁(上)
在Java5中,专门提供了锁对象,利用锁可以方便的实现资源的封锁,用来控制对竞争资源并发访问的控制,这些内容主要集中在java.util.concurrent.locks 包下面,里面有三个重要的接口 ...
- PHP 获取网上文件内容
<?php $ch = curl_init("http://game.qq.com/comm-htdocs/js/game_area/moba_server_select.js&quo ...
- div垂直居中的问题
工作和面试时常常会遇到怎么设置div垂直居中与浏览器中:包括固定宽高和不固定宽高的 1.固定宽高的div垂直居中 宽高固定的div很容易设置让其垂直居中 <div class="cen ...
- 一个关于qml插件的文章-转
制作Qt Quick 2 Extension Plugin的几个问题-Qt 经过几天的google和爬帖,加上自己的摸索,终于把新版的Qt Quick 2制作插件的问题给弄了个明白,工作流可以建立了. ...
- 表单_post提交方式和get的区别,元素集
提交方式及表单域的name属性 使用form表单一种是post提交方式,一种是get提交方式,它们以method属性来定义,如果没有指定method属性,默认get方式提交. 表单域必须配合name属 ...
- HookSSDT 通过HookOpenProcess函数阻止暴力枚举进程
首先要知道Ring3层调用OpenProcess的流程 //当Ring3调用OpenProcess //1从自己的模块(.exe)的导入表中取值 //2Ntdll.dll模块的导出表中执行ZwOpen ...
- C#多线程学习之(五)使用定时器进行多线程的自动管理
本文实例讲述了C#多线程学习之使用定时器进行多线程的自动管理.分享给大家供大家参考.具体分析如下: Timer类:设置一个定时器,定时执行用户指定的函数. 定时器启动后,系统将自动建立一个新的线程,执 ...