UVa Live Archive 2519 - Radar Installation
来源:互联网 发布:搜索引擎优化的方法 编辑:程序博客网 时间:2024/05/17 01:07
传送门UVa Live Archive 2519 - Radar Installation
题意:找出最小的雷达数。
一开始我的贪心策略是从左到右依次放雷达,然后判断右边那个点是否在这个雷达里。
但是这个策略是错的
比如有(0,2)和(1,3)两个点.雷达半径为3,按照我的思路,第一个中心点应选sqrt(3²-2²),这样包含第二个点还需要另一个雷达,而实际上只需要一个圆心在(1,0)的雷达就可以了.所以这种思路是错误的.
所以这题要算出每个点在X轴上的左极限和右极限,在它们之间的雷达都可以覆盖到,这样就变成了在N个区间里,选择最少的点,使每个区间都包含。
这样的话,对每个区间的右端点进行排序,取第一个点的右端点为t,如果下一个点的左端点大于t,说明这个雷达不能覆盖,要新建一个雷达,这时候它的坐标应该是目前点的右端点,这样就能确保选择的点最少。
详情见代码
#include <cstdio>#include <algorithm>#include <cmath>using namespace std;const int MAXN = 1000 + 100;struct POINT{double left, right;friend bool operator < (const POINT &a, const POINT &b){return a.right < b.right;}}point[MAXN];int main(){//freopen("input.txt", "r", stdin);int n, i, j, cases = 1, cnt, a, b;double r;bool flag;while (scanf("%d%lf", &n, &r), n || r){flag = false;cnt = 1;for (i = 0; i < n; i++){scanf("%d%d", &a, &b);if (abs(b) > r)flag = true;point[i].left = a - sqrt(r * r - b * b);point[i].right = a + sqrt(r * r - b * b);}printf("Case %d: ", cases++);if (flag)printf("-1\n");else{sort(point, point + n);double temp = point[0].right;for (i = 1; i < n; i++){if (temp < point[i].left){temp = point[i].right;cnt++;}}printf("%d\n", cnt);}}return 0;}
0 0
- UVa Live Archive 2519 - Radar Installation
- uva-2519 - Radar Installation
- UVALive - 2519 Radar Installation
- UVALive - 2519 Radar Installation
- UVALive - 2519 Radar Installation
- Uva-Live Archive-3635-Pie
- Radar Installation
- Radar Installation
- Radar Installation
- Radar Installation
- Radar Installation
- Radar Installation
- Radar Installation
- Radar Installation
- Radar Installation
- Radar Installation
- Radar Installation
- Radar Installation
- oracle job的管理
- Hadoop入门进阶步步高(六)-Hadoop1.x与Hadoop2的区别
- C++程序设计
- 一个简单的翻色棋游戏
- PAT1001. A+B Format
- UVa Live Archive 2519 - Radar Installation
- oracle 传输表空间
- JAVA开发的网页式看图软件
- 多表关联查询(Oracle)
- linux(rhel)远程win rdesktop pkgconfig(xcb) >= 1.1.92
- 让控件失去焦点
- internet explorer 8安装尚未完成解决办法
- Spring 框架的设计理念与设计模式分析
- *.cs怎样生成为*.dll wsdl