POJ1328 Radar Installation(贪心)
题目链接。
题意:
给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住。求最少使用圆的数量。
分析:
贪心。
首先把所有点 x 坐标排序, 对于每一个点,求出能够满足的 最靠右的圆心,即雷达的位置。
要保证雷达左面的点都被覆盖,如果不能覆盖就向左移,移到能将左边未覆盖的覆盖。如果后面的店不在雷达的覆盖区,则再加一雷达。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <cmath> using namespace std; const int maxn = + ; struct Pos{
double x, y;
bool operator < (const Pos &rhs) const {
return (x < rhs.x || (x == rhs.x && y > rhs.y));
}
}pos[maxn]; int main() {
int n1, n, d, kase = ;
bool flag;
while(scanf("%d %d", &n1, &d) == ) {
if(n1 == && d == ) break;
n = ;
flag = true;
for(int i=; i<n1; i++) {
cin >> pos[n].x >> pos[n].y;
if(pos[n].y > d) flag = false;
else n++;
} if(d <= ) flag = false; sort(pos, pos+n); int cnt = ;
double t, a, a1; a = pos[].x + sqrt(d*d - pos[].y*pos[].y); for(int i=; i<n && flag; i++) {
double x = pos[i].x, y = pos[i].y; t = d*d - y*y;
a1 = x + sqrt(t); if(x < a && a1 < a)
a = a1;
else if((x-a)*(x-a)+y*y > d*d) {
a = a1;
cnt++;
}
} printf("Case %d: ", ++kase);
if(!flag) printf("-1\n");
else printf("%d\n", cnt);
} return ;
}
POJ1328 Radar Installation(贪心)的更多相关文章
- poj1328 Radar Installation —— 贪心
题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...
- [POJ1328]Radar Installation
[POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one si ...
- POJ--1328 Radar Installation(贪心 排序)
题目:Radar Installation 对于x轴上方的每个建筑 可以计算出x轴上一段区间可以包含这个点 所以就转化成 有多少个区间可以涵盖这所有的点 排序之后贪心一下就ok 用cin 好像一直t看 ...
- POJ1328 Radar Installation 【贪心·区间选点】
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 54593 Accepted: 12 ...
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- POJ1328——Radar Installation
Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...
- POJ1328 Radar Installation 解题报告
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- Radar Installation(贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56826 Accepted: 12 ...
- Radar Installation 贪心
Language: Default Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42 ...
随机推荐
- android抓包工具
下载 http://gdown.baidu.com/data/wisegame/2158469c63492e89/Tcpzhuabao_2.apk
- redis 自启动脚本
看到网上许多手写的亦或复制的redis开机自启动脚本, 版本好多, 其实最简单的可以从下载的redis文件里找得到 我下载的redis是 3.0.3 版本的, 对于其他版本, 没有详细查看, 有需要 ...
- 一道在知乎很火的 Java 题——如何输出 ab【转】
这是一个源自知乎的话题,原贴链接:一道百度的面试题,有大神会嘛? 虽然我不是大神,但我也点进去看了一下,思考了一会之后有了一些思路,然后去看其它人的答案的时候果然全都已经被各路大神们先想到并贴出来了, ...
- mysql sql语句大全(2)
1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server --- 创建 备份 ...
- GridView布局及适配器优化
1.布局样式 <GridView android:id="@+id/gridView" android:layout_width="fill_parent" ...
- (Excel导出失败)检索COM类工厂中CLSID为{00024500-0000-0000-C000-000000000046}的组件时失
在DCOM 中不存在WORD.EXCEL等OFFICE组件 最近在做一个关于office转存PDF的Web项目.开发过程一切顺利. 起初在网上找到一些Word,PPT转PDF的代码.很好用.一切顺 ...
- ASP.NET实现从服务器下载文件2
转:http://lanhy2000.blog.163.com/blog/static/436786082011105104110713/ 假设在服务器的根目录下有个名为Download的文件夹 ...
- CoreLocation+MapKit系统定位(含坐标以及详细地址)
iOS8 之后出现一些新的配置 [self.manager requestWhenInUseAuthorization]; 并且在info.plist文件中增加 NSLocationWhenInUse ...
- Java面试——基础
1,作用域,Java只有public,protect,private,默认是default相当于friendly 作用域 当前类 同一package 子类 其它 ...
- Android单位度量
px(像素):屏幕上的点. in(英寸):长度单位.mm(毫米):长度单位.pt(磅):1/72英寸.dp(与密度无关的像素):一种基于屏幕密度的抽象单位.在每英寸160点的显示器上,1dp = 1p ...