poj 1328 Radar Installation(贪心+快排)
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 题意:将一条海岸钱看为X轴,X轴的上方为大海,海上有许多岛屿,给出岛屿的位置与雷达的覆盖半径,要求在海岸线上建雷达,
在雷达能够覆盖所有岛的基础上,求最少需要多少雷达。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;
#define MAX 1005
struct sea
{
double left;
double right;
} a[];
bool operator < (sea A,sea B)
{
return A.left<B.left;
}
int main()
{
int n,k=;
double d;
while(cin>>n>>d&&(n||d))
{
bool flag=false;
for(int i=; i<n; i++)
{
double x,y;
cin>>x>>y;
if(fabs(y)>d)
flag=true;
else
{ //计算区间
a[i].left=x*1.0-sqrt(d*d-y*y);
a[i].right=x*1.0+sqrt(d*d-y*y);
}
}
printf("Case %d: ",k++);
if(flag)
printf("-1\n");
else
{
int ans=; //雷达初始化
sort(a,a+n); // 排序
double s=a[].right;
for(int i=; i<n; i++)
{
if(a[i].left>s)
{
ans++; //雷达加一
s=a[i].right; // 更新右端点
}
else if(a[i].right<s)
s=a[i].right;
}
printf("%d\n",ans);
}
}
return ;
}
poj 1328 Radar Installation(贪心+快排)的更多相关文章
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- 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 ...
- POJ 1328 Radar Installation 贪心 难度:1
http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...
- poj 1328 Radar Installation(贪心)
题目:http://poj.org/problem?id=1328 题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...
- POJ 1328 Radar Installation 贪心题解
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...
- POJ 1328 Radar Installation#贪心(坐标几何题)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- poj 1328 Radar Installation (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
随机推荐
- Linux系统挂载只读改成读写
1.mount命令可用于查看哪个模块输入只读,一般显示为: [root@localhost ~]# mount /dev/cciss/c0d0p2 on / type ext3 (rw) proc o ...
- java爬取网页Unicode转UTF-8中文
unicode编码简而言之就是将每一个字符用16位2进制数标识.但是通常都用4位的16进制数标识. 例如: 1)中文字符串"你好"的unicode码为:\u60\u597d; 2) ...
- mybatis进阶--mapper输入映射和输出映射
我们知道,mapper.xml是我们配置操作数据库的sql语句的地方.其中每个sql语句对应着一个方法,每个方法都有自己的输入输出参数类型.那么这些类型都是怎么配置的呢?今天我们来一起学习下. 输入映 ...
- iOS push新的调用方法
// IOS8 新系统需要使用新的代码if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){ [[UIAppl ...
- Jackson高并发情况下,产生阻塞
情况:在高并发情况下,查看线程栈信息,有大量的线程BLOCKED. 从线程栈得知,线程栈中出现了阻塞,锁在了com.fasterxml.jackson.databind.ser.SerializerC ...
- 部署描述符(web.xml)和标注(annotation)
部署描述符(web.xml) 详细信息可在http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html上下载web- ...
- Statement、PreparedStatement、CallableStatement的区别
此三个接口的声明如下: public interface Statement extends Wrapper, AutoCloseable public interface PreparedState ...
- oracle使用3DES加密
CREATE OR REPLACE PACKAGE dbc_cryptor IS SYSKEY VARCHAR2(16) := '0000000012345678'; SYSIV VARCHAR2(1 ...
- fastcgi协议解析(nginx)
请求NGINX ->[ {(post data) +> (NGX_HTTP_FASTCGI_STDIN)} * N +> {(environment variables) +> ...
- ubuntu14上安装nltk
安装nltk 1)在buntu终端命令键入:wget https://bootstrap.pypa.io/ez_setup.py,下载ez_setup.py. 2)下载完成后后,键入:sudo py ...