POJ 1328 Radar Installation 区间贪心
来源:互联网 发布:php-> 编辑:程序博客网 时间:2024/06/15 10:36
对于每座岛屿,求出可能的雷达范围,也就是一个区间。(以岛屿为中心,d为半径画圆,与x轴的左交点就是区间的做断电,右交点就是右端点)
对于得到的区间按照x递增,x相同y递增的规则排序。
然后从前往后扫描,求出重叠区域,在重叠区域放置雷达。不断循环下去即可。
#include <set>#include <map>#include <queue>#include <stack>#include <cmath>#include <cstdio>#include <cstdlib>#include <iostream>#include <algorithm>#define EPS 1e-10#define MAX_N 30000#define Pi acos(-1.0)#define INF 0x3f3f3f3fusing namespace std;struct data{ double l, r;//一定要写成double bool operator < (const data& b) const { return l < b.l || (l == b.l && r < b.r); }};int n;double d;data dat[MAX_N];int solve(){ sort(dat, dat + n); int res = 0; double L = dat[0].l, R = dat[0].r;//刚开始写成int,wa了 for (int i = 0; i < n; i++) { //找相交区间 if (dat[i].l <= R && dat[i].r >= R) L = dat[i].l; else if (dat[i].l <= R && dat[i].r <= R) { L = dat[i].l; R = dat[i].r; } else { res++; L = dat[i].l; R = dat[i].r; } } return res + 1;}int main (){ //freopen ("in.txt", "r", stdin); //freopen ("out.txt", "w", stdout); int Case = 1; while (~scanf("%d%lf", &n, &d)) { if (!n && !d) break; bool has_ans = true; for (int i = 0; i < n; i++) { double x, y; scanf("%lf%lf", &x, &y); if (y > d) has_ans = false; else { dat[i].l = x - sqrt((double)(d * d - y * y)); dat[i].r = x + sqrt((double)(d * d - y * y)); } } printf("Case %d: ", Case++); if (!has_ans || d <= 0) printf("-1\n"); else printf("%d\n", solve()); } return 0;}
0 0
- POJ 1328 Radar Installation(区间贪心)
- POJ 1328 Radar Installation【贪心 区间问题】
- POJ 1328(Radar Installation 区间贪心)
- [POJ 1328] Radar Installation (区间贪心)
- POJ 1328 Radar Installation 贪心区间选点
- POJ 1328 Radar Installation 区间贪心
- POJ 1328 Radar Installation 区间贪心
- poj-1328 Radar Installation(贪心+区间选点)
- poj Radar Installation 【贪心 区间】
- [ACM] POJ 1328 Radar Installation (贪心,区间选点问题)
- poj 1328 Radar Installation 【贪心】【区间选点问题】
- 【贪心专题】POJ 1328 G - Radar Installation (区间覆盖)
- POJ - 1328 Radar Installation (贪心,区间选点问题)
- POJ 1328 Radar Installation(贪心+区间选点问题)
- POJ 1328 Radar Installation 贪心(区间选点)
- POJ 1328 Radar Installation 贪心最少区间问题
- POJ 1328 Radar Installation(区间覆盖、贪心)
- POJ 1328 Radar Installation (贪心,区间选点问题)
- theano scan 实例
- Android Studion 中的错误 Plugin Error
- CSS属性
- Android SQLite SQL语句高级进阶
- Linux内核分析01-分析汇编代码理解计算机是如何工作
- POJ 1328 Radar Installation 区间贪心
- 哈希表用于数据索引
- JAVA学习的第二天
- Dropout资源【3】
- MVCPager 的PagerOptions属性
- 职责链模式(23)
- 配置内核支持U盘
- UVALive 6582 Magical GCD (数学+数据结构) -- 解题报告
- bzoj1087[SCOI2005]互不侵犯King