NOIp2017 Cheese
那么长时间了,,,,后天就要去华师参加夏令营了...然而今天才做出来这道题...就是一个搜索.
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
using namespace std;
const int MAXN=1e3+1;
double x[MAXN],y[MAXN],z[MAXN];
bool vis[MAXN];
queue<int>q;
double dist(int u,int v)
{
double dx=x[u]-x[v],dy=y[u]-y[v],dz=z[u]-z[v];
return sqrt(dx*dx+dy*dy+dz*dz);
}
int main()
{
int t;scanf("%d",&t);
while(t--)
{
memset(vis,0,sizeof(vis));
while(!q.empty())q.pop();
int n,h,is=0;double r;
scanf("%d %d %lf",&n,&h,&r);
for(int i=1;i<=n;i++)
{
scanf("%lf %lf %lf",&x[i],&y[i],&z[i]);
if(z[i]+r>=h && z[i]-r<=0)is=1;
if(z[i]-r<=0){
q.push(i);
vis[i]=true;
}
}
while(!q.empty()){
int u=q.front();q.pop();
if(z[u]+r>=h){
is=1;break;
}
for(int v=1;v<=n;v++){
if(v!=u && !vis[v] && dist(u,v)<=r*2){
vis[v]=true;
q.push(v);
}
}
}
if(is==1)printf("Yes\n");
else printf("No\n");
}
return 0;
}