POJ 1328 Radar Installation 贪心题解】的更多相关文章

本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 3 以这个圆推断能够包含右边的多少个圆,直到不能够包含下一个点,那么继续第2步,画一个新圆. 看代码吧,应该非常清晰直观的了. 效率是O(n),尽管有嵌套循环.可是下标没有反复.一遍循环就能够了.故此是O(n). #include <stdio.h> #include <cmath>…
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…
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 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…
http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆心允许范围,问题转化为在许多圆心允许范围内取尽可能少的点,也即在许多线段上取尽可能少的点,使得所有线段上都有点被取到 3.从左往右考虑,完全在左边的线段肯定要取点,如果这个点在当前线段上已经取了,明显就可以忽略当前线段,明显在线段上的最优点是右端点 #include <iostream> #inc…
题目:http://poj.org/problem?id=1328   题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范围为d,问至少需要多少个雷达能监测到多有的小岛. 思路:从左到右把每个小岛的放置雷达的区间求出,按结束点排序,从左至右看,当发现下一个区间的起始点大于前面所有区间的最小结束点的时候,答案加一. #include <stdio.h> #include<string.h> #include…
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; struct node { double l,r; //找到以岛为圆心,以d为半径的圆与坐标x轴的左交点l.右交点r //雷达只有设在l~r之间,岛才在雷达覆盖范围内 }a[]; int cmp(node a,node b) { return a.l<…
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知道, 问最少需要多少个雷达覆盖所有的岛屿. (错误)思路:我开始是想从最左边的点雷达能探测的到的最右的位置出发,判断右边其余的点是否与该点距离小于d 是,岛屿数-1:不是,雷达数+1,继续... (正确)思路:每个岛屿的座标已知,以雷达半径为半径画圆,与x轴有两个交点. 也就是说,若要覆盖该岛,雷达…
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…
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…
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…
解题思路:给出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: 1000MS   Memory Limit: 10000K Total Submissions: 43490   Accepted: 9640 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 poin…
POJ 1328 题意: 将一条海岸线看成X轴,X轴上面是大海,海上有若干岛屿,给出雷达的覆盖半径和岛屿的位置,要求在海岸线上建雷达,在雷达能够覆盖全部岛屿情况下,求雷达的最少使用量. 分析: 贪心法,先研究一下每个岛屿,设岛屿到海岸线的垂直距离为d,雷达的覆盖半径为k,若d>k,直接输出-1,若d<=k,则雷达的建造有一个活动区间[x1,x2](用平面几何可以求得出来).因此,在可以覆盖的情况下每个岛屿都有一个相应的活动区间.该问题也就转变成了最少区间选择问题即: 在n个区间中选择一个区间集…
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 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…
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 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 54143   Accepted: 12178 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…
题目链接: http://poj.org/problem?id=1328 题意: 在x轴上有若干雷达,可以覆盖距离d以内的岛屿. 给定岛屿坐标,问至少需要多少个雷达才能将岛屿全部包含. 分析: 对于每个岛屿,计算出可以包含他的雷达所在的区间,找到能包含最多岛屿的区间即可. 可以看出这是一个典型的区间问题,我们有几种备选方法: (1)优先选取右端点最大的区间. (2)优先选取长度最长的区间. (3)优先选取与其他区间重叠最少的区间. 2.3很容易想到反例,而1则是正确的,端点越靠右,剩下的区间就越…
题目链接:http://poj.org/problem?id=1328 题意:给出海上有n个小岛的坐标,求发出的信号可以覆盖全部小岛的最少的雷达个数.雷达发射信号是以雷达为圆心,d为半径的圆,雷达都在x轴上. 分析:1.刚开始就知道这道题要用贪心做,但是一下子想不出该如何贪心.然后图图画画后发现只要求出可以覆盖每一个小岛的雷达的区间范围即可,然后可以转化为贪心区间求点问题.正好今天在复习贪心思想时在紫书上看到这个例子啦~(紫书P233) 2.贪心区间求点,就是排序后尽量选择重合区间多的地方选择放…
贪心 #include<algorithm> #include<iostream> #include<cstdio> #include<cmath> using namespace std; struct Radar { double start,end; } radar[]; bool cmp(Radar a,Radar b) { return a.start<b.start; } int main() { int n,d,x,y,m,num,fla…
翻出一年多前的代码看,发现以前的代码风格很糟糕 题意:给你n个点 m为圆的半径,问需要多少个圆能把全部点圈到 #include <iostream> #include <algorithm> #include <cmath> using namespace std; struct ss{ double x,y; }a[1005]; int cmp(ss x,ss y) { if(x.x==y.x)return x.y<y.y; else return x.x<…
1.Link: http://poj.org/problem?id=1328 http://bailian.openjudge.cn/practice/1328/ 2.Content: Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 52833   Accepted: 11891 Description Assume the coasting is an infinite straig…
题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围.这个范围可用勾股定理求得.记录每个点的范围,然后排序,贪心. (由于不熟悉qsort的用法,折腾了一个小时.后来清晰了:qsort 的cmp是通过正负判断(但结构体又不是),而sort的cmp是通过对错判断,即0或1.所以qsort的cmp用‘-’(结构体除外),sort的cmp用‘<’和‘>’…
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: 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…
题目:http://poj.org/problem?id=1328 题意:给定海岛个数,雷达半径,输入各个海岛坐标,求能覆盖所有海岛的最少雷达数 题解: 1. 贪心的区间覆盖问题,尽量让每个雷达覆盖更多岛屿数. 2. 需要将题目转换一下,将海岛坐标,转换为,能够覆盖他的所有雷达圆心的区间, 然后对区间按照起点位置升序排序. 3. 定义一个最右点 end,依次判断所有区间,如果 end < sec[i].start,更新雷达位置,雷达数++:否则如果 end > sec[i].end,更新雷达位…
题目地址:http://poj.org/problem?id=1328 Sample Input 3 2 1 2 -3 1 2 1 1 2 0 2 0 0 Sample Output Case 1: 2 Case 2: 1 参考博客地址:http://www.cnblogs.com/jackge/archive/2013/03/05/2944427.html分析:一个岛屿坐标(x,y),在x轴上会存在一个线段区间,在这个线段区间内任意位置放置雷达都可以.int dd=sqrt(d*d-y*y);…