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. Figure A Sample Input of Radar Installations
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) ...
随机推荐
- fatal error: openssl/sha.h: No such file or directory 解决方案
出现这个或者fatal error: openssl/名单.h: No such file or directory.都是没有安装libssl-dev- libssl-dev包含libraries, ...
- Unique Paths [LeetCode]
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- 选择列表中的列无效,因为该列没有包含在聚合函数或 GROUP BY 子句中
选择列表中的列无效,因为该列没有包含在聚合函数或 GROUP BY 子句中 T-SQL核心语句形式: SELECT --指定要选择的列或行及其限定 [INTO ] --INTO子句 ...
- SAP销售订单状态修改(审核) 计划行自动产生需求,产生MD04需求
不知道业务怎么配置的,创建销售单时,一堆计划行类别,什么CN,DN...都有,但是审核后需要计划行变更为CP,这样在MD04才能看到需求. 原有逻辑是弄个后台程序,审核后调一下,更新一下计划行,这样是 ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon
C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Mysql复制表格
1.复制表结构及数据到新表 CREATE TABLE 新表 as SELECT * FROM 旧表 不过这种方法的一个最不好的地方就是新表中没有了旧表的primary key.Extra(auto_i ...
- 22. Generate Parentheses——本质:树,DFS求解可能的path
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- BZOJ2492 Revenge of Fibonacci
首先我们高精度加法算出前10W个数... 然后把所有的前40位搞出来建成trie树,于是就变成了模板题了... 说一下...这题要是直接建出来son[tot][10]会MLE...所以...建trie ...
- 创建link server链接服务器碰到的问题及解决办法
问题描述 今天在做数据库迁移,然后新建link server(链接服务器)的时候,碰到以下问题. 我的sql 脚本是这样的. 然后,执行的时候就收到以下错误信息. Msg 468, Level 16, ...
- tortoisegit教程
tortoisegit教程: http://www.mamicode.com/info-detail-311565.html https://my.oschina.net/longxuu/blog/1 ...