就是一个简单的DFS,跟题解中DFS的唯一区别也就是预处理了邻接点吧...WA在最后一个点,经测不是精度问题,头秃
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define mp(x, y) make_pair(x, y)
#define FOR(x, y, z) for (int x = y; x <= z; x++)
typedef long long ll;
int t;
ll n, h, r;
#define N 1003
#define e 0.0001
struct hole
{
ll x, y, z;
hole() = default;
hole(ll x, ll y, ll z) : x(x), y(y), z(z) {}
} holes[N];
double dist(const hole &a, const hole &b)
{
return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2) + pow(a.z - b.z, 2));
}
vector<int> nxt[N];
bool vis[N];
bool dfs(int x)
{
vis[x] = true;
if (holes[x].z + r >= h)
return true;
for (auto v : nxt[x])
if (!vis[v] && dfs(v))
return true;
return false;
}
int main()
{
cin >> t;
while (t--)
{
cin >> n >> h >> r;
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= n; i++)
{
nxt[i].clear();
ll x, y, z;
cin >> x >> y >> z;
holes[i] = hole(x, y, z);
}
for (int i = 1; i < n; i++)
for (int j = i + 1; j <= n; j++)
if (dist(holes[i], holes[j]) <= 2*r + e)
{
nxt[i].push_back(j);
nxt[j].push_back(i);
}
bool ok = false;
for (int i = 1; i <= n; i++)
if (!vis[i] && holes[i].z - r <= e && dfs(i))
{
ok = true;
break;
}
if (ok)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
请大佬指教