poj1328 Radar Installation 区间贪心】的更多相关文章

题目大意: 在X轴选择尽量少的点作为圆心,作半径为d的圆.使得这些圆能覆盖所有的点. 思路: 把每个点都转化到X轴上.也就是可以覆盖这个点的圆心的位置的范围[a,b].然后按照每个点对应的a从小到大排序.第一点需要特殊处理,我们赋值r=b0 .也就是使得第一个圆的圆心的横坐标尽量大.然后遍历剩下的点.对于i点,如果该点的ai大于r, 就需要增加一个圆,圆心为bi :否则的话,把r更新为r与bi中小的值. 代码: #include<iostream> #include<cstdio>…
Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 54593   Accepted: 12292 Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point loca…
题目:Radar Installation 对于x轴上方的每个建筑 可以计算出x轴上一段区间可以包含这个点 所以就转化成 有多少个区间可以涵盖这所有的点 排序之后贪心一下就ok 用cin 好像一直t看了好多blog 改了scanf 过了 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> #include<cmat…
https://vjudge.net/problem/POJ-1328 贪心策略选错了恐怕就完了吧.. 一开始单纯地把island排序,然后想从左到右不断更新,其实这是错的...因为空中是个圆弧. 后来知道了通过对每个island求雷达范围,将这些范围排序,但是去重策略也没想对.因为有两种情况,都需要更新t值,但是只有一种需要ans++. #include<iostream> #include<cstdio> #include<queue> #include<cs…
对每个岛屿,能覆盖它的雷达位于线段[x-sqrt(d*d-y*y),x+sqrt(d*d+y*y)],那么把每个岛屿对应的线段求出来后,其实就转化成了经典的贪心法案例:区间选点问题.数轴上有n个闭区间[ai,bi],取尽量少的点,使得每个区间内都至少有一个点.选法是:把区间按右端点从小到大排序(右端点相同时按左端点从大到小),然后每个没选的区间选最右边的一个点即可. #include<iostream> #include<cstdio> #include<cstdlib>…
[POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can onl…
解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的位置在x轴上,所以我们设雷达的坐标为(x,0),对于任意一个岛屿p(a,b),因为岛屿要满足在雷达的覆盖范围内,所以 (x-a)^2+b^2=r^2,解得 xmin=a-sqrt(r*r-b*b);//即为区间的左端点 xmax=a+sqrt(r*r-b*b);//即为区间的右端点 接下来区间选点即…
Radar Installation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total Submission(s) : 22   Accepted Submission(s) : 9 Problem Description Assume the coasting is an infinite straight line. Land is in one side of coa…
Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 54798   Accepted: 12352 Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point loca…
Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only…
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island…
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, s…
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, s…
Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 56702   Accepted: 12792 Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point loca…
Radar Installation 原文是English,直接上中文 Descriptions: 假定海岸线是无限长的直线.陆地位于海岸线的一侧,海洋位于另一侧.每个小岛是位于海洋中的一个点.对于任何一个雷达的安装 (均位于海岸线上),只能覆盖 d 距离,因此海洋中的小岛被雷达安装所覆盖的条件是两者间的距离不超过 d . 我们使用卡笛尔坐标系,将海岸线定义为 x 轴.海洋的一侧位于 x 轴上方,陆地的一侧位于下方.给定海洋中每个小岛的位置,并给定雷达安装的覆盖距离,您的任务是写一个程序,找出雷…
题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围.这个范围可用勾股定理求得.记录每个点的范围,然后排序,贪心. (由于不熟悉qsort的用法,折腾了一个小时.后来清晰了:qsort 的cmp是通过正负判断(但结构体又不是),而sort的cmp是通过对错判断,即0或1.所以qsort的cmp用‘-’(结构体除外),sort的cmp用‘<’和‘>’…
题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足的 最靠右的圆心,即雷达的位置. 要保证雷达左面的点都被覆盖,如果不能覆盖就向左移,移到能将左边未覆盖的覆盖.如果后面的店不在雷达的覆盖区,则再加一雷达. #include <iostream> #include <cstdio> #include <cstdlib> #i…
题目链接: http://poj.org/problem?id=1328 题意: 在x轴上有若干雷达,可以覆盖距离d以内的岛屿. 给定岛屿坐标,问至少需要多少个雷达才能将岛屿全部包含. 分析: 对于每个岛屿,计算出可以包含他的雷达所在的区间,找到能包含最多岛屿的区间即可. 可以看出这是一个典型的区间问题,我们有几种备选方法: (1)优先选取右端点最大的区间. (2)优先选取长度最长的区间. (3)优先选取与其他区间重叠最少的区间. 2.3很容易想到反例,而1则是正确的,端点越靠右,剩下的区间就越…
POJ 1328 题意: 将一条海岸线看成X轴,X轴上面是大海,海上有若干岛屿,给出雷达的覆盖半径和岛屿的位置,要求在海岸线上建雷达,在雷达能够覆盖全部岛屿情况下,求雷达的最少使用量. 分析: 贪心法,先研究一下每个岛屿,设岛屿到海岸线的垂直距离为d,雷达的覆盖半径为k,若d>k,直接输出-1,若d<=k,则雷达的建造有一个活动区间[x1,x2](用平面几何可以求得出来).因此,在可以覆盖的情况下每个岛屿都有一个相应的活动区间.该问题也就转变成了最少区间选择问题即: 在n个区间中选择一个区间集…
ZOJ地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=360 POJ地址:http://poj.org/problem?id=1328 解题思路:贪心 ];                  : -;  }         ;                     && r == ){                       }          lose = ;          d = (        …
Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 68578   Accepted: 15368 Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point loca…
Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 106491   Accepted: 23648 Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point loc…
Input The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n li…
建模:二维转一维:贪心 Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d…
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知道, 问最少需要多少个雷达覆盖所有的岛屿. (错误)思路:我开始是想从最左边的点雷达能探测的到的最右的位置出发,判断右边其余的点是否与该点距离小于d 是,岛屿数-1:不是,雷达数+1,继续... (正确)思路:每个岛屿的座标已知,以雷达半径为半径画圆,与x轴有两个交点. 也就是说,若要覆盖该岛,雷达…
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation…
Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 56826   Accepted: 12814 Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point loca…
Language: Default Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42461   Accepted: 9409 Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small islan…
Radar Installation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total Submission(s) : 54   Accepted Submission(s) : 28 Problem Description Assume the coasting is an infinite straight line. Land is in one side of co…
Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 9485 Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locat…