Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 56826 | Accepted: 12814 |
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
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
struct island
{
double x , y ;
double left , right ;
}a[];
int n ;
int d ;
bool cmp (island a , island b)
{
return a.x < b.x ;
} int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
int cnt ;
int ans = ;
bool flag ; while (~ scanf ("%d%d" , &n , &d)) {
if (n == && d == )
break ;
flag = ; for (int i = ; i < n ; i++) {
scanf ("%lf%lf" , &a[i].x , &a[i].y) ;
if (a[i].y > 1.0 * d || a[i].y < || d <= ) {
flag = ;
}
if (!flag) {
a[i].left = (double) a[i].x - sqrt (1.0 * d * d - a[i].y * a[i].y) ;
a[i].right = (double) a[i].x + sqrt (1.0 * d * d - a[i].y * a[i].y) ;
}
}
if (flag) {
printf ("Case %d: -1\n" , ans++) ;
continue ;
}
sort (a , a + n , cmp) ;
cnt = ;
double l = a[].left , r = a[].right ;
for (int i = ; i < n ; i++) {
if (a[i].left > r) {
cnt++ ;
l = a[i].left ;
r = a[i].right ;
}
else {
l = a[i].left ;
r = a[i].right < r ? a[i].right : r ;
}
}
printf ("Case %d: %d\n" , ans++ , cnt) ;
}
return ;
}
别忘记每次都要跟新放radar的区间 ,orz
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 贪心
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轴的圆 ...
随机推荐
-
jdk动态代理实现
1.jdk动态代理的简单实现类 package com.proxy; import java.lang.reflect.InvocationHandler; import java.lang.refl ...
-
【转】jQuery中.bind() .live() .delegate() .on()的区别
bind(type,[data],fn) 为每个匹配元素的特定事件绑定事件处理函数 $("a").bind("click",function(){alert(& ...
-
任务中使用wget,不保存文件
*/20 * * * * wget --output-document=/dev/null http://www.domain.com 使用wget每过20分钟访问一次,不保存访问文件内容
-
Owin中间件搭建OAuth2.0认证授权服务体会
继两篇转载的Owin搭建OAuth 2.0的文章,使用Owin中间件搭建OAuth2.0认证授权服务器和理解OAuth 2.0之后,我想把最近整理的资料做一下总结. 前两篇主要是介绍概念和一个基本的D ...
-
elasticsearh 中每个节点中需要有相同的插件
elasticsearh 中每个节点中需要有相同的插件 [2016-09-13 19:25:24,049][INFO ][discovery.zen ] [node02] failed to send ...
-
docker 指定容器名字
docker:/root# docker run -itd --name linux123 ubuntu /bin/bash Unable to find image 'ubuntu:latest' ...
-
android 布局常用混淆属性
1.如何控制某一控件在父控件中的相对位置呢? 在Android系统中提供了layout_margin,用来控制某一控件边缘相对于父控件的边距. 其中, android:layout_marginTop ...
-
hdu4414(DFS 找十字架数量)
Problem Description The Nazca Lines are a series of ancient geoglyphs located in the Nazca Desert in ...
-
WebService基础学习(三)&mdash;CXF
一.什么是CXF? Apache CXF = Celtix + Xfire,开始叫 Apache CeltiXfire,后来更名为 Apache CXF 了,以下简称为 CXF.Apache ...
-
android学习笔记--AlarmManager
AlarmManager称呼为全局定时器,有的称呼为闹钟.其实它的作用和Timer有点相似. 都有两种相似的用法: (1)在指定时长后执行某项操作(2)周期性的执行某项操作 AlarmManager ...