#include<iostream>
#include<algorithm>
#include<cmath>
#define eps 1e-9
/*
* AUTHOR :benbendog
* DATE : 2010/12/23
* PROBLEM: many sprinklers has it own sprinkling range, find the minimum sprinklers
* that can cover the area of w x h
* SOLUTION: turn the sprinker's range (circle ) to a segment, because we
* only need to consider those area needing sprinkled.
* use greedy (from right to left ) , suppose cur is
* the most left position sprinkled, we
* choose the remaining segment whose s.right >=cur & cur - s.left
* is the longest.
* CAUTION : precision problem
*
*/
using namespace std;
struct segment
{
double f,t;
};
int cmp(const struct segment & a,const struct segment & b);
int main()
{
int i,n,w,h;
while(cin>>n)
{
cin>>w>>h;
int s[n][2],cnt = 0,c = 0;
double t,hh;
segment seg[n];
hh = (double)h/2.0;
hh = hh*hh;
for(i = 0 ; i< n ;++i)
{
cin>>s[i][0]>>s[i][1];
t = sqrt((double)s[i][1]*s[i][1] - hh);
seg[cnt].f = s[i][0] - t;
seg[cnt].t = s[i][0] + t;
if(seg[cnt].f <=w && seg[cnt].t >= eps)cnt++;
}
sort(seg,seg+cnt,cmp);
double cur = w;
// find segment which has seg.t >= cur
i = 0;
while(i < cnt && cur > 1e-9)
{
int ind = -1;
double big = 0;
while(i < cnt && seg[i].t >=cur)
{
if((cur - seg[i].f) > big)
{
ind = i;
big = cur - seg[i].f;
}
i++;
}
if(ind==-1)break;
c++;
cur-=big;
}
if(cur > 1e-9)cout<<-1<<endl;
else
cout<<c<<endl;
}
return 0;
}
int cmp(const struct segment & a,const struct segment & b)
{
return a.t > b.t;
}
- Dec 23 Thu 2010 14:22
UVA 10382
全站熱搜
留言列表