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 ...
随机推荐
- web系统架构的演进变化很形象
随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. 单一应用架构 当网站流量很小时,只需一个应用, ...
- 一种解决的方法:CGContextSaveGState: invalid context 0x0
遇到这个问题找了好久答案,最后排错排出来了 CGContextSaveGState: invalid context 0x0. This is a serious error. This applic ...
- Reso | The Linux Command Line 的中文版
http://book.haoduoshipin.com/tlcl/book/zh/ 本书是 The Linux Command Line 的中文版, 为大家提供了多种不同的阅读方式. 中英文双语版- ...
- [转] 条件变量(Condition Variable)详解
http://www.wuzesheng.com/?p=1668 条件变量(Condtion Variable)是在多线程程序中用来实现“等待->唤醒”逻辑常用的方法.举个简单的例子,应用程序A ...
- POJ 2653 Pick-up sticks (判断线段相交)
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 10330 Accepted: 3833 D ...
- 异步tcp通信——APM.Server 消息推送服务的实现
消息推送服务 服务器推送目前流行就是私信.发布/订阅等模式,基本上都是基于会话映射,消息对列等技术实现的:高性能.分布式可以如下解决:会话映射可采用redis cluster等技术实现,消息对列可使用 ...
- html.ex.day01
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 用angular来思考问题How do I “think in AngularJS” if I have a jQuery background?
[翻译]How do I “think in AngularJS” if I have a jQuery background? 1. 不要先设计页面,然后再使用DOM操作来改变它的展现 在jQuer ...
- Linq101-Set
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Set { / ...
- Linq101-Restriction
using System; using System.Linq; namespace Linq101 { class Restriction { /// <summary> /// Thi ...