POJ 1328 Radar Installation Posted on 2018-09-12 | In ACM | 阅读 预处理出每个岛所能容许的雷达范围,按照右端点排序,每次都新放置一个在新线段的右边,然后往后找哪个的左端点够不着了,再放在这个线段的右端点,以此类推 C++ Code 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <math.h>using namespace std;struct land{ double l; double r; int y; bool operator<(const land& b) const{ if(r == b.r){ return l < b.l; } return r < b.r; }}lands[1000];int main(){ int n, d; int cas = 1; bool flag = true; int cnt = 1; while(~scanf("%d%d", &n, &d) && n != 0){ flag = true; cnt = 1; int x; for(int i = 0; i < n; i++){ scanf("%d%d", &x, &lands[i].y); if(lands[i].y > d || lands[i].y < 0) flag = false; lands[i].l = x - sqrt(d*d - lands[i].y*lands[i].y); lands[i].r = x + sqrt(d*d - lands[i].y*lands[i].y); } if(flag == false){ printf("Case %d: %d\n", cas++, -1); continue; } sort(lands, lands+n); double cur = lands[0].r; for(int i = 1; i < n; i++){ if(lands[i].l > cur){ cur = lands[i].r; cnt++; } } printf("Case %d: %d\n", cas++, cnt); } return 0;}