文章目录 题目信息解题思路代码实现 题目信息 题目传送门 解题思路 找出一个处于奶酪下表面的点,枚举相邻点找到合法状态后再dfs一遍就ok了 代码实现 #include <bits/stdc++.h> using namespace std; const int N = 1005; struct pos { double x, y, z; } p[N]; long long t, n, r, h; bool a[N], f; // 求两点是否相邻 inline bool dis(pos a, pos b) { long long s = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z-b.z); return s <= 4 * r * r; } void F(int x) { // 标记为true(上表面),退出去 if (f == true) { return ; } // 上表面,标记为true if (p[x].z + r >= h){ f = true; return ; } for (int i = 1; i <= n; ++i) { // 跑过这个点就跳过(记忆化) if (a[i] == true) { continue; } // 没跑过且相邻,跑! if (dis(p[x], p[i])) { a[i] = true; F(i); } } } int main() { cin >> t; while (t--) { // 不要忘记重置标记哦 f = 0; cin >> n >> h >> r; for (int i = 1; i <= n; ++i) { cin >> p[i].x >> p[i].y >> p[i].z; a[i] = false; } for (int i = 1; i <= n; ++i) { // 下表面,起跑 if (p[i].z <= r){ a[i] = true; F(i); } } if (f == true) { cout << "Yes\n"; } else { cout << "No\n"; } } return 0; }