喷水装置(二)
时间限制:3000 ms | 内存限制:65535 KB
难度:4
描述
有一块草坪,横向长w,纵向长为h,在它的橫向中心线上不同位置处装有n(n<=10000)个点状的喷水装置,每个喷水装置i喷水的效果是让以它为中心半径为Ri的圆都被润湿。请在给出的喷水装置中选择尽量少的喷水装置,把整个草坪全部润湿。
输入
第一行输入一个正整数N表示共有n次测试数据。
每一组测试数据的第一行有三个整数n,w,h,n表示共有n个喷水装置,w表示草坪的横向长度,h表示草坪的纵向长度。
随后的n行,都有两个整数xi和ri,xi表示第i个喷水装置的的横坐标(最左边为0),ri表示该喷水装置能覆盖的圆的半径。
输出
每组测试数据输出一个正整数,表示共需要多少个喷水装置,每个输出单独占一行。
如果不存在一种能够把整个草坪湿润的方案,请输出0。
样例输入
2
2 8 6
1 1
4 5
2 10 6
4 5
6 5
样例输出
1
2
/*
描述:南阳理工OJ_12
日期:2018-11-17
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
struct Solution
{
int pStart;
int pEnd;
};
bool compare(const Solution &s1,const Solution &s2)
{
return s1.pStart < s2.pStart;
}
int getResault(vector<Solution> &resault,const float w)
{
sort(resault.begin(),resault.end(),compare);
int number = 0;
float myMin = 0.0,myMax = 0.0;
for(vector<Solution>::iterator it = resault.begin(); it != resault.end(); it++)
{
if(it->pStart > myMax)
return 0;
else
{
if(it->pEnd <= myMax)
continue;
else
{
float temp = myMax;
for(;it != resault.end(); it++)
{
if(it->pStart <= myMax)
{
if(it->pEnd >= temp)
temp = it->pEnd;
}
else
{
it--;
break;
}
}
myMax = temp;
number++;
if(myMax >= w)
break;
}
}
}
if(myMax < w)
return 0;
else
return number;
}
int main()
{
int N;
cin>>N;
for(int i=0; i<N; i++)
{
int n,w,h;
cin>>n>>w>>h;
vector<Solution> resault;
for(int j=0; j<n; j++)
{
int px,rx;
cin>>px>>rx;
if(rx > h/2.0)
{
float gap = sqrt(rx*rx - (h*h)/4.0);
Solution tempSolu = {px - gap,px + gap};
resault.push_back(tempSolu);
}
}
cout<<getResault(resault,w)<<endl;
}
return 0;
}