@[BayernFans](/space/show?uid=80883)
# 希望更丰富的展现?使用Markdown
by RiverFun @ 2018-10-02 18:44:17
@[Steve_braveman](/space/show?uid=96570) 大佬求助
by __Pillar @ 2018-10-02 19:01:10
@[BayernFans](/space/show?uid=80883)
```cpp
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
long long int t,n,h,r;
struct p {
int x,y,z;
} hole[1010];
struct o {
int next,to;
} way[1000010];
int cnt=0;
int head[1010];
void add(int u,int v) {
cnt++;
way[cnt].to=v;
way[cnt].next=head[u];
head[u]=cnt;
}
int main() {
cin>>t;
while(t--) {
cnt=0;
cin>>n>>h>>r;
int up[n+5];
int vis[n+5];
int ppp=0;
memset(head,0,sizeof(head));
memset(up,0,sizeof(up));
memset(vis,0,sizeof(vis));
queue<int>q;
for(int i=1; i<=n; i++) {
cin>>hole[i].x>>hole[i].y>>hole[i].z;
if(hole[i].z-r<=0) {
q.push(i);
vis[i]=1;
}
if(hole[i].z+r>=h) up[i]=1;
if(hole[i].z-r<=0&&hole[i].z+r>=h) {
cout<<"Yes"<<endl;
ppp=1;
break;
}
}
if(ppp==1) continue;
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
if(i==j) continue;
if(4rr>=(hole[j].x-hole[i].x)(hole[j].x-hole[i].x)+(hole[j].y-hole[i].y)(hole[j].y-hole[i].y)+(hole[j].z-hole[i].z)*(hole[j].z-hole[i].z)) {
add(i,j);
add(j,i);
}
}
}
int yyy=0;
while(!q.empty()) {
int u=q.front();
q.pop();
for(int i=head[u]; i; i=way[i].next) {
int v=way[i].to;
vis[v]=1;
if(up[v]==1) {
yyy=1;
cout<<"Yes"<<endl;
break;
}
if(vis[v]==0) q.push(v);
}
if(yyy==1) break;
}
if(yyy==1) continue;
if(yyy==0) cout<<"No"<<endl;
}
return 0;
}
```
顺便说一句,我这道题用的是并查集
by RiverFun @ 2018-10-02 19:03:58
@[Steve_braveman](/space/show?uid=96570) 大佬您改了那个地方啊……
by __Pillar @ 2018-10-02 19:37:20
@[BayernFans](/space/show?uid=80883)
我不是跟你说了嘛,我用的是并查集,你这个算法我没改,我只是转换成Markdown格式
by RiverFun @ 2018-10-02 19:41:39
@[Steve_braveman](/space/show?uid=96570) 好吧,谢谢大佬
by __Pillar @ 2018-10-02 19:46:22