UVA
来源:互联网 发布:淘宝密码对的登不上 编辑:程序博客网 时间:2024/06/01 09:33
几何专场中的一道题目
其实更是贪心
更定每一个圆后计算左右能覆盖的边界
然后贪心处理
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <string>#include <cmath>#include <set>#include <map>#include <stack>#include <queue>#include <ctype.h>#include <vector>#include <algorithm>#include <sstream>#define PI acos(-1.0)// cout << " === " << endl;using namespace std;typedef long long ll;const int maxn = 10000 + 7, INF = 0x3f3f3f3f, mod = 1e9+7;int n, L, h;double c;struct node { double o, r; double l_, r_;}a[maxn];bool cmp(node a, node b) { if(a.l_ == b.l_) return a.r_ < b.r_; return a.l_ < b.l_;}void init() { for(int i = 0; i < n; ++i) { scanf("%lf%lf", &a[i].o, &a[i].r); if(a[i].r <= c) { a[i].l_ = a[i].r_ = 0; } else { double t = sqrt((a[i].r)*(a[i].r) - (c)*(c)); a[i].l_ = a[i].o - t; a[i].r_ = a[i].o + t; } } sort(a, a+n, cmp);}void solve() { double ansl = 0.0, ansr = 0.0; if(a[0].l_ > ansl) { cout << -1 << endl; return; } int i = 0, cnt = 0; while(1) { while(a[i].l_ <= ansl) { ansr = max(ansr, a[i].r_); i++; if(i >= n) break; } cnt++; if(ansr >= L) { cout << cnt << endl; return; } if(ansl == ansr) { cout << -1 << endl; return; } ansl = ansr; }}int main() { while(scanf("%d%d%d", &n, &L, &h) != EOF && n) { c = (h/2.0); init(); solve(); } return 0;}