poj 1328 Radar Installation
2016-09-25 23:20
323 查看
题意:给出n个点和圆的半径d,在x轴上放置圆(圆心在x轴上),问最少要放多少个圆才能把所有点覆盖?如果不能全部覆盖输出 -1。点都在x轴上方。
分析:当有 yi > d 的时候,输出 -1,否则把所有点排序,然后从左往右贪心放圆即可。
分析:当有 yi > d 的时候,输出 -1,否则把所有点排序,然后从左往右贪心放圆即可。
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; #define x first #define y second typedef pair<double, double> point; const int N = 2000; point p ; int n, d; int main() { //freopen("in.txt", "r", stdin); int cas = 0; while(scanf("%d%d", &n, &d) != EOF) { if(n == 0 && d == 0) break; bool nosul = false; for(int i = 0; i < n; i++) { scanf("%lf%lf", &p[i].x, &p[i].y); if(p[i].y > d) { nosul = true; } } printf("Case %d: ", ++cas); if(nosul) { puts("-1"); } else { sort(p, p + n); int ans = 1; double tmp = sqrt(d * d - p[0].y * p[0].y); double rx = p[0].x + tmp; for(int i = 1; i < n; i++) { tmp = sqrt(d * d - p[i].y * p[i].y); double tmplx = p[i].x - tmp; double tmprx = p[i].x + tmp; /* 这样判也可以,不过会被卡精度,两种判法本质上一样 rx = min(rx, tmprx); if((p[i].x - rx) * (p[i].x - rx) + p[i].y * p[i].y > d * d + 1e-6) { ans++; rx = tmprx; } */ if(tmplx > rx) { ans++; rx = tmprx; } else { rx = min(rx, tmprx); } } printf("%d\n", ans); } } return 0; }
相关文章推荐
- poj 1328
- poj1328 Radar Installation
- poj 1328 Radar Installation (贪心)
- POJ-1328
- poj 1328 贪心
- POJ 1328
- POJ 1328 Radar Installation(贪心)
- zoj 1360 || poj 1328 Radar Installation
- POJ 1328 Radar Installation
- 贪心 POJ 1328 Radar Installation
- POJ 1328 Radar Installation(贪心)
- 区间贪心·POJ 1328·Radar Installation
- POJ1328解题报告
- POJ 1328 Radar Installation(贪心)
- poj 1328 Radar Installation(贪心)
- poj 贪心相关之1328 Radar Installation
- POJ 1328 Radar Installation 贪心
- POJ1328,Radar Installation,贪心,仰慕逆向思维
- POJ-1328-Radar Installation
- poj 1328 && nyoj 287 Radar Installation【贪心】