bzoj2517 矩形覆盖

题意

二分半径,递归判断当前矩形是否能被覆盖。

code:

#include<bits/stdc++.h>
using namespace std;
const int maxn=55;
const double eps=1e-6;
int T,K;
double n,m;
struct node{double x,y,r;}a[maxn],b[maxn];
inline int read()
{
    char c=getchar();int res=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')res=res*10+c-'0',c=getchar();
    return res*f;
}
inline double sqr(double x){return x*x;}
inline bool check(double x,double y,int id)
{
	double d=sqr(b[id].x-x)+sqr(b[id].y-y);
	return d<=sqr(b[id].r);
}
bool check(double x1,double x2,double y1,double y2)
{
	bool flag[4]={0,0,0,0};
	if(fabs(x1-x2)<=eps&&fabs(y1-y2)<=eps)return 1;
	for(int i=1;i<=K;i++)
	{
		bool in[4]={0,0,0,0};
		in[0]=check(x1,y1,i);
		in[1]=check(x2,y1,i);
		in[2]=check(x1,y2,i);
		in[3]=check(x2,y2,i);
		if(in[0]&&in[1]&&in[2]&&in[3])return 1;
		for(int j=0;j<4;j++)flag[j]|=in[j];
	}
	for(int i=0;i<4;i++)if(!flag[i])return 0;
	double midx=(x1+x2)/2.0,midy=(y1+y2)/2.0;
	return check(x1,midx,y1,midy)&&check(midx,x2,y1,midy)&&check(x1,midx,midy,y2)&&check(midx,x2,midy,y2);
}
inline bool check(double mid)
{
	for(int i=1;i<=K;i++)b[i]=a[i],b[i].r*=mid;
	return check(0.0,n,0.0,m);
}
inline void solve()
{
	K=read(),n=read(),m=read();
	for(int i=1;i<=K;i++)a[i].x=read(),a[i].y=read(),a[i].r=read();
	double l=0,r=n*m;
	while(r-l>eps)
	{
		double mid=(l+r)/2.0;
		if(check(mid))r=mid;
		else l=mid;
	}
	printf("%.3lf\n",l);
}
int main()
{
	T=read();
	while(T--)solve();
	return 0;
}
posted @ 2020-06-04 11:07  nofind  阅读(133)  评论(0编辑  收藏  举报