题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=12
第二次写
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<=(b);++i)
#define REPD(i,a,b) for(int i=a;i>=(b);--i)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
struct Aug
{int x1,x2;bool operator < (const Aug& p) const {return x1<p.x1;}
}A[10000+5];
int main(int argc, char const *argv[])
{int T; scanf("%d",&T);while(T--){int n; double w,h; scanf("%d%lf%lf",&n,&w,&h);double x,r; int cnt=0;REP(i,1,n){scanf("%lf%lf",&x,&r);if(r*2<=h) continue;double s=sqrt(r*r-h*h/4);A[cnt++]=Aug{x-s,x+s};}sort(A,A+cnt);int ans=0,pos=0; double L=0.0;for(;;){REP(i,pos,cnt-1){if(A[i].x1<=L) A[i].x1=L;else break;}double R=0.0;if(pos<cnt&&A[pos].x1==L) while(pos<cnt&&A[pos].x1==L) R=max(R,A[pos].x2),pos++;else break;if(R==0.0||L>=w) break;L=R; ans++; }printf("%d\n", L>=w?ans:0);}return 0;
}