Radar Installation(贪心)
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.

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轴的圆 ...
随机推荐
- 关于sql 的convert 格式设置
CONVERT(data_type,expression[,style]) convert(varchar(10),字段名,转换格式) 说明:此样式一般在时间类型(datetime,smalldate ...
- [转] Sublime Text 3支持GB2312和GBK编码
Sublime Text 3与Sublime Text 2的不同 其实有不少人写过如何让Sublime Text 2支持GB2312和GBK编码,例如这篇.基本原理就是先装好Package Contr ...
- php检测php.ini是否配制正确
运行命令行 php -d display_startup_errors=1 -d error_reporting=-1 -d display_errors -c "C:\path-to-ph ...
- xcode更新,想想也是醉了
每次更新,都要整个文件全部更新,这下载速度,想想也是醉了,苹果你就不能搞了更新包吗!!
- jsonp的后台怎么返回去数据
- nth-child() 选择器
给tabel tb1 td添加样式 #tb1 tr td:nth-child(2n+1) {/*奇数行样式*/ } #tb1 tr td:nth-child(2n) {/*偶数行样式*/ }
- 编写高质量代码改善C#程序的157个建议[匿名类型、Lambda、延迟求值和主动求值]
前言 从.NET3.0开始,C#开始一直支持一个新特性:匿名类型.匿名类型由var.赋值运算符和一个非空初始值(或以new开头的初始化项)组成.匿名类型有如下基本特性: 1.既支持简单类型也支持复杂类 ...
- AngularJS开发指南1:AngularJS简介
什么是 AngularJS? AngularJS 是一个为动态WEB应用设计的结构框架.它能让你使用HTML作为模板语言,通过扩展HTML的语法,让你能更清楚.简洁地构建你的应用组件.它的创新点在于, ...
- OC基础--OC中的类方法和对象方法
PS:个人感觉跟C#的静态方法和非静态方法有点类似,仅仅是有点类似.明杰老师说过不要总跟之前学过的语言做比较,但是个人觉得,比较一下可以加深印象吧.重点是自己真的能够区分开! 一.OC中的对象方法 1 ...
- 关于 Maven 的插件maven-war-plugin
在进行项目发布的时候,可能会碰到这样的情况, 希望在保持项目源代码不变的前提下,希望能够针对不同的运行环境获得相应的运行包.(比如war包) 基本配置 :(包括排除 不想打进war包的jar 的配置) ...