uva10382 -Watering Grass
来源:互联网 发布:网络市场调研的含义 编辑:程序博客网 时间:2024/05/18 00:23
题意:
一长l宽w的草坪,水平中心线上有n个位置pi可安装喷水装置,其覆盖范围为以半径ri为圆。求最少需要多少个喷水装置。
思路:
首先,每个装置在长方形草坪上的有效覆盖面积为 左边界pos - sqrt((r*r - w*w / 4.0 ))到右边界 pos + sqrt((r*r - w*w / 4.0 ))宽l的长方形。这样记录下有效区间后此题就可转为经典区间覆盖问题。
代码如下:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int N = 10005;int n;double l, w;struct spr { double x, y;}d[N];int cmp(spr a, spr b){ return a.x < b.x ? 1 : 0;}int main(){ while (~scanf("%d%lf%lf", &n, &l,&w)) { double pos, r; int len = 0; for (int i = 0; i < n; i++) { scanf("%lf%lf", &pos, &r); if (r > w / 2) { d[len].x = pos - sqrt((r*r - w*w / 4.0 )); d[len].y = pos + sqrt((r*r - w*w / 4.0 )); len++; } } sort(d, d + len, cmp); int ans = 0, flag = 0; double left = 0, right = 0; if (d[0].x <= 0) { int i = 0; while (i < len) { int j = i; while (j < len&& d[j].x <= left) { if (right < d[j].y) right = d[j].y; j++; } if (j == i) break; ans++; i = j; left = right; if (left >= l) { flag = 1; break; } } } if (flag) printf("%d\n", ans); else printf("-1\n"); } return 0;}
0 0
- uva10382 - Watering Grass
- Uva10382 Watering Grass
- [贪心]UVA10382 Watering Grass
- uva10382 -Watering Grass
- UVA10382 Watering Grass (贪心)
- UVA10382-Watering Grass(贪心)
- uva10382 - Watering Grass(给草浇水)
- uva10382 - Watering Grass(区间覆盖变形)
- UVA10382- Watering Grass(区间覆盖问题)
- Watering Grass
- UVa 10382 Watering Grass
- UVa 10382 - Watering Grass
- UVa 10382 - Watering Grass
- uva 10382 - Watering Grass
- uva 10382 - Watering Grass
- Uva 10382 - Watering Grass
- UVAOJ--10382 Watering Grass
- 10382 - Watering Grass
- RxJava中的常用操作符
- 学习android前配置
- ObQueryNameString routine
- git diff的用法
- Educational Codeforces Round 7 E. Ants in Leaves(DFS+贪心)
- uva10382 -Watering Grass
- 跑步与巨流河
- 9.UITableView的设置
- UI基础-02 Xcode中的iOS工程模板
- 基础HTML练习
- UI基础-03 应用剖析
- 【信息资源管理之宏观了解】
- 《SSH客户端连接服务器(SecureCRT)》
- HTML视频笔记