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…
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…
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…
题目:http://poj.org/problem?id=1328   题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范围为d,问至少需要多少个雷达能监测到多有的小岛. 思路:从左到右把每个小岛的放置雷达的区间求出,按结束点排序,从左至右看,当发现下一个区间的起始点大于前面所有区间的最小结束点的时候,答案加一. #include <stdio.h> #include<string.h> #include…
http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆心允许范围,问题转化为在许多圆心允许范围内取尽可能少的点,也即在许多线段上取尽可能少的点,使得所有线段上都有点被取到 3.从左往右考虑,完全在左边的线段肯定要取点,如果这个点在当前线段上已经取了,明显就可以忽略当前线段,明显在线段上的最优点是右端点 #include <iostream> #inc…
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 3 以这个圆推断能够包含右边的多少个圆,直到不能够包含下一个点,那么继续第2步,画一个新圆. 看代码吧,应该非常清晰直观的了. 效率是O(n),尽管有嵌套循环.可是下标没有反复.一遍循环就能够了.故此是O(n). #include <stdio.h> #include <cmath>…
(- ̄▽ ̄)-* #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: 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…