标签:
2 2 8 6 1 1 4 5 2 10 6 4 5 6 5
1 2
解题思路:这个题目最重要的是转化思路,将面积覆盖转化成区间覆盖就可以了。
/*
对于区间覆盖:首先定一个起点star。找出排序后起点小于等于star的所有区间,找出
终点最大的一个区间,作为新的起点star。重复上述操作,得到最少需要的区间数量。
*/
#include<bits/stdc++.h>
using namespace std;
struct SEG{
double left,right;
}seg[10100];
bool cmp(SEG a,SEG b){
if(a.left!=b.left)
return a.left<b.left;
return a.right>b.right;
}
int main(){
int t,i,j,k,n,w,h,xi,ri,cnt;
double dx,tmp,star;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&w,&h);
tmp=h*h/4.0; //转化思路,将圆的覆盖面积,转化为线段的区间覆盖
for(i=0;i<n;i++){
scanf("%d%d",&xi,&ri);
dx=ri*ri-tmp;
if(dx<0){
i--,n--; //技巧
continue;
}
dx=sqrt(dx);
seg[i].left=xi-dx;
seg[i].right=xi+dx;
}
//区间覆盖
sort(seg,seg+n,cmp);
star=0;cnt=0;k=-1;
while(star<w&&star>=seg[k+1].left){
double maxx=-1;
for(i=k+1;i<n&&star>=seg[i].left;i++){
if(maxx<seg[i].right){
maxx=seg[i].right;
k=i;
}
}
star=maxx;
cnt++;
}
if(star<w) cout<<0<<endl;
else cout<<cnt<<endl;
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/chengsheng/p/4626479.html