P3958 [NOIP2017 提高组] 奶酪
代码:
#include<bits/stdc++.h>
using namespace std;
struct Bal
{
int x,y,z;
bool operator >(Bal a)
{
return z>a.z;
}
bool operator <(Bal a)
{
return z<a.z;
}
bool operator ==(Bal a)
{
return z==a.z;
}
};
bool Tou(int x,int y,int z,int d)
{
double x1=double(x),y1=double(y),z1=double(z),d1=double(d);
return sqrt(x1*x1+y1*y1+z1*z1)<=d1;
}
int main()
{
int a;
cin>>a;
for(int A=0;A<a;A++)
{
int b,c,d;
cin>>b>>c>>d;
Bal Fil[b];
for(int B=0;B<b;B++)
{
cin>>Fil[B].x>>Fil[B].y>>Fil[B].z;
}
sort(Fil,Fil+b);
int e=0,f=b;
while(Fil[e].z<=d)
{
e++;
}
if(e==0)
{
cout<<"No"<<endl;
continue;
}
while(Fil[f-1].z+d>=c)
{
f--;
}
if(f==b)
{
cout<<"No"<<endl;
continue;
}
if(e>=f)
{
cout<<"Yes"<<endl;
continue;
}
queue<int> Bfs;
for(int B=0;B<e;B++)
{
Bfs.push(B);
}
bool Vis[b]={false};
for(int B=0;B<e;B++)
{
Vis[B]=true;
}
bool Rea=false;
while(!Bfs.empty())
{
for(int B=0;B<b;B++)
{
if(Tou(Fil[B].x-Fil[Bfs.front()].x,Fil[B].y-Fil[Bfs.front()].y,Fil[B].z-Fil[Bfs.front()].z,2*d) && !Vis[B])
{
if(B>=f)
{
Rea=true;
break;
}
Bfs.push(B);
Vis[B]=true;
}
}
if(Rea)
{
break;
}
Bfs.pop();
}
if(Rea)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
}