标签:
2 2 8 6 1 1 4 5 2 10 6 4 5 6 5
1 2
1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 #include <algorithm> 5 using namespace std; 6 7 const int maxn = 10000 + 5; 8 9 struct node{ 10 double a, b; 11 }A[maxn]; 12 13 int cmp(node A, node B){ 14 return A.a < B.a; 15 } 16 17 int main(){ 18 int T; 19 scanf("%d", &T); 20 while(T--){ 21 int n, w, h, cnt = 0, x, r; 22 scanf("%d%d%d", &n, &w, &h); 23 double start = 0, h1 = h*h*1.0/4, l; 24 for(int i = 0; i < n; i++){ 25 scanf("%d%d", &x, &r); 26 if(r*r < h1){ 27 i--; n--; 28 continue; 29 } 30 l = sqrt(r*r - h1); 31 A[i].a = x-l > 0 ? x-l : 0; 32 A[i].b = x+l < w ? x+l : w; 33 } 34 sort(A, A+n, cmp); 35 int i, k = -1; 36 while(start < w && A[k+1].a <= start){ 37 double max1 = -1; 38 for(i = k+1; A[i].a <= start && i < n; i++){ 39 if(max1 < A[i].b){ 40 max1 = A[i].b; 41 k = i; 42 } 43 } 44 start = max1; 45 cnt++; 46 } 47 printf("%d\n", start < w ? 0 : cnt); 48 } 49 }
标签:
原文地址:http://www.cnblogs.com/hsq666/p/4575270.html