标签:
2
2 8 6
1 1
4 5
2 10 6
4 5
6 5
1
2
思路:求出每个区间的左右端点, 然后按左端点排序;
从左到右扫一遍就好。
#include <bits/stdc++.h> using namespace std; const int maxn = 605; struct uct { double left, right; }; bool cmp(uct a, uct b) { if(a.left == b.left) { return a.right > b.right; } return a.left < b.left; } int main() { ios::sync_with_stdio(false); uct s[maxn]; int n, t; cin >> t; while(t--) { double r, w, h, x; cin >> n >> w >> h; h = h*1.0/2; for(int i = 0; i < n; i++) { cin >> x >> r; if(r > h) { double y = r*r - h*h; s[i].left = max(x - sqrt(y), 0.0); s[i].right = min(x + sqrt(y), w); } else { s[i].left = x; s[i].right = x; } } sort(s, s+n, cmp); int cnt = 0; double start = 0; int i = -1; while(start < w && s[i+1].left <= start) { double MAX = -1; for(int j = i + 1; s[j].left <= start && j < n; j++) { if(MAX < s[j].right){ MAX = s[j].right; i = j; } } start = MAX; cnt++; } if(start >= w) cout << cnt << endl; else cout << 0 << endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/cshg/p/5689647.html