POJ1328 Radar Installation
2012-10-10 09:38
337 查看
原题传送:http://poj.org/problem?id=1328
贪心。
每个岛屿在海岸线上都有一个雷达覆盖区间[x - sqrt(r2 - y2), x + sqrt(r2 - y2)],将这些区间按左区间从小到大排序,选择第一个区间,然后在后面找能够重叠的区间,如果能够重叠,那么更新该区间的右端点(取小的),遍历一遍就完事儿了。
(ps:有时候调了精度反而会wa)
View Code
贪心。
每个岛屿在海岸线上都有一个雷达覆盖区间[x - sqrt(r2 - y2), x + sqrt(r2 - y2)],将这些区间按左区间从小到大排序,选择第一个区间,然后在后面找能够重叠的区间,如果能够重叠,那么更新该区间的右端点(取小的),遍历一遍就完事儿了。
(ps:有时候调了精度反而会wa)
View Code
#include <stdio.h> #include <math.h> #include <string.h> #include <algorithm> #define N 1005 const double eps = 1e-8; struct node { double x, y; }e ; struct nd { double s, t; bool operator < (const nd &tmp) const { return s < tmp.s; } }a ; int main() { double r; int n, i, flag, cas = 1, cnt; while(scanf("%d%lf", &n, &r)) { if(n == 0 && r < eps) break; for(flag = i = 0; i < n; i ++) { scanf("%lf%lf", &e[i].x, &e[i].y); if(e[i].y > r) flag = 1; } if(flag == 1 || r < 0) { printf("Case %d: -1\n", cas ++); continue; } for(i = 0; i < n; i ++) { a[i].s = e[i].x - sqrt(r * r - e[i].y * e[i].y); a[i].t = e[i].x + sqrt(r * r - e[i].y * e[i].y); } std::sort(a, a + n); double s = a[0].s; double t = a[0].t; for(cnt = i = 1; i < n; i ++) { if((a[i].s >= s && a[i].s <= t) || (a[i].t >= s && a[i].t <= t)) // 不调精度才AC { t = std::min(t, a[i].t); } else { cnt ++; s = a[i].s; t = a[i].t; } } printf("Case %d: %d\n", cas ++, cnt); } return 0; }
相关文章推荐
- poj 1328 Radar Installation(贪心)
- poj 1328
- POJ 1328 Radar Installation(贪心)
- poj 1328 Radar Installation
- poj 1328 Radar Installation 贪心
- POJ 1328 Radar Installation
- poj 1328 Radar Installation
- Radar Installation(POJ-1328)
- poj1328(贪心)
- POJ 1328 Radar Installation
- POJ 1328 贪心 Radar Installation
- 【贪心专题】POJ 1328 G - Radar Installation (区间覆盖)
- poj 1328 Radar Installation
- POJ 1328 -Radar Installation
- poj1328 -贪心雷达问题
- POJ 1328 Radar Installation(雷达安装)__贪心
- poj 1328 Radar Installation(nyoj 287 Radar):贪心
- poj 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation