张琪曼等人用时空雷达定位李旭琳所在的空间位置。如图7.3所示,时空雷达装在一条直线上,直线上方是空间海洋,每个人在空间海洋的位置就如同大海中的岛屿,这些人的位置已知,每一个雷达的扫描范围是一个半径为d的圆形区域,问最少需要多少个雷达覆盖所有的人(岛屿)。
标签:
Description
Input
Output
Sample Input
3 2 1 2 -3 1 2 1 1 2 0 2 0 0
Sample Output
Case 1: 2 Case 2: 1
这道题目与下面的题目有异曲同工之妙
#include <iostream> #include <algorithm> #include <cmath> #include <cstdio> using namespace std; const int maxn = 1005; struct uct { double left, right; }; bool cmp(uct a, uct b) { return a.left < b.left; } int main() { ios::sync_with_stdio(false); uct s[maxn]; int k = 0, n, R; while(cin >> n >> R) { int flag = 1; if(n == 0&& R == 0) break; for(int i = 0; i < n; i++){ int x, y; cin >> x >> y; if(abs(y) <= R){ double len = sqrt((R*R - y*y)*1.0); s[i].left = x - len; s[i].right = x + len; }else flag = 0; //cout << i <<" " <<x <<" " <<y << endl; } if(flag) { sort(s, s+n, cmp); int cnt = 1; double ends = s[0].right; for(int i = 0; i < n; i++){ if(s[i].left > ends){ ends = s[i].right; cnt++; }else if(s[i].right < ends){ ends = s[i].right; } } cout << "Case " << ++k << ": " << cnt << endl; } else cout << "Case " << ++k << ": " << -1 << endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/cshg/p/5693660.html