UVA - 10382 Watering Grass 贪心
2017-08-08 09:09
381 查看
题意明了
覆盖面的话 这里精度要求不是很细,可以求出每个圆能覆盖的左右边界
然后贪心选取,,规则就是左边界能覆盖的前提下 记录最大右边界,
OK
覆盖面的话 这里精度要求不是很细,可以求出每个圆能覆盖的左右边界
然后贪心选取,,规则就是左边界能覆盖的前提下 记录最大右边界,
OK
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<set> #include<stack> #include<algorithm> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const int maxn = 10000 + 7, INF = 0x3f3f3f3f, mod = 1e9+7; int n; double l_, w_, max_; struct node { double p, R; double l, r; }a[maxn]; bool cmp(node a, node b) { return a.l <= b.l; } void init() { max_ = 0; for(int i = 0; i < n; ++i) { scanf("%lf%lf", &a[i].p, &a[i].R); if(a[i].R <= w_/2) { a[i].l = 0; a[i].r = 0; continue; } double d = sqrt(a[i].R * a[i].R - (w_*w_/4)); a[i].l = a[i].p - d; a[i].r = a[i].p + d; max_ = max(max_, a[i].r); } sort(a, a+n, cmp); } void solve() { if(a[0].l > 0 || max_ < l_) { cout << -1 << endl; return; } int ans = 0; double s = 0, r_ = 0; for(int i = 0; i < n;) { int j = i; while(a[j].l <= s) { r_ = max(r_, a[j].r); j++; } if(i == j) { cout << -1 << endl; return; } ans++; s = r_; //r_ = 0; if(s >= l_) break; i = j; } cout << ans << endl; } int main() { while(scanf("%d%lf%lf", &n, &l_, &w_) != EOF && n) { init(); solve(); } return 0; }
相关文章推荐
- UVA 10382 - Watering Grass 贪心
- UVA - 10382 Watering Grass (区间覆盖 贪心)
- UVA 10382 Watering Grass (贪心 + 区间覆盖问题)
- UVa 10382 - Watering Grass(贪心+区间覆盖问题)
- UVA 10382 - Watering Grass 贪心
- UVa 10382 - Watering Grass (贪心—区间覆盖)
- uva--10382Watering Grass+贪心
- UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】
- UVA10382-Watering Grass-贪心 NYOJ6-喷水装置(一)-贪心
- uva 10382 - Watering Grass(贪心)
- UVA - 10382 Watering Grass 贪心(几何)
- uva 10382 Watering Grass_贪心
- UVa 10382 Watering Grass 解题报告(贪心 最小覆盖)
- uva 10382 Watering Grass_贪心
- UVa 10382 Watering Grass (区间覆盖贪心问题+数学)
- 10382 - Watering Grass uva贪心
- Uva 10382 (区间覆盖) Watering Grass
- UVa 10382 - Watering Grass
- UVa 10382 - Watering Grass(贪心算法,区间覆盖问题)
- UVa:10382 Watering Grass