[Luogu] P3958 奶酪
Luogu P3958 奶酪
这个题暴力可过【手动微笑】。好像据我知道的有BFS啦,DFS啦,还有并查集。不管你怎么写,反正我写的DFS
【再次手动微笑】。首先读入数据,遍历每一个未访问的空洞进行DFS,再按距离判断哪个空洞可以继续到达,最后判断圆心高度加半径是否大于等于奶酪高度即可(即\(hole[i].z + r \geqslant h\))。哎,可怜一个水题,我竟然考场上爆炸,还是太水啦。
#include <algorithm>
#include <cstdio>
#include <cmath>
typedef long long ll;
int T, n, h, r, stp, vis[1001];
bool fnd;
double tmp;
struct che{
int x, y, z;
bool operator < (const che &chi)const{return z < chi.z;}
}c[1001];
inline double dist(int now, int i) {
return sqrt(double(c[now].x - c[i].x) * (c[now].x - c[i].x) +
double(c[now].y - c[i].y) * (c[now].y - c[i].y) +
double(c[now].z - c[i].z) * (c[now].z - c[i].z));
}
void dfs(int now) {
if(c[now].z + r >= h) {
fnd = true;
return ;
}
vis[now] = stp;
for (int i = 1; i <= n; ++i) {
tmp = dist(now, i);
if(tmp <= r * 2 && vis[i] != stp && !fnd)
dfs(i);
}
return ;
}
void solve() {
fnd = false;
scanf("%d%d%d", &n, &h, &r);
for (int i = 1; i <= n; ++i)
scanf("%d%d%d", &c[i].x, &c[i].y, &c[i].z);
std::sort(c + 1, c + n + 1);
for (int i = 1; i <= n; ++i)
if(!fnd && std::abs(c[i].z) - r <= 0 && vis[i] != stp)
dfs(i);
if(fnd) printf("Yes\n");
else printf("No\n");
return ;
}
int main() {
scanf("%d", &T);
while(T--) {
stp++;
solve();
}
return 0;
}