大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说奶酪【BFS】_法国有多少种奶酪,希望能够帮助大家进步!!!
点从z=0为起点,想跑到z=h,只能在球内,或者是球表层上跑,问能否从起点跑到终点?
直接暴力bfs判断即可。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
//#include <unordered_map>
//#include <unordered_set>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define eps 1e-8
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
#define MP(a, b) make_pair(a, b)
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef long long ll;
const int maxN = 1e3 + 7;
ll h, r;
int N;
struct node
{
ll x, y, z;
node(ll a=0, ll b=0, ll c=0):x(a), y(b), z(c) {}
inline void In() { scanf("%lld%lld%lld", &x, &y, &z); }
} a[maxN];
ll _Dis2(node e1, node e2) { return (e1.x - e2.x) * (e1.x - e2.x) + (e1.y - e2.y) * (e1.y - e2.y) + (e1.z - e2.z) * (e1.z - e2.z); }
bool vis[maxN];
queue<int> Q;
inline bool bfs()
{
while(!Q.empty()) Q.pop();
for(int i=1; i<=N; i++)
{
if(a[i].z <= r)
{
vis[i] = true;
Q.push(i);
}
}
int u;
while(!Q.empty())
{
u = Q.front(); Q.pop();
if(a[u].z + r >= h) return true;
for(int i=1; i<=N; i++)
{
if(vis[i]) continue;
if(_Dis2(a[u], a[i]) <= 4LL * r * r)
{
vis[i] = true;
Q.push(i);
}
}
}
return false;
}
int main()
{
int T; scanf("%d", &T);
while(T--)
{
scanf("%d%lld%lld", &N, &h, &r);
for(int i=1; i<=N; i++) a[i].In();
for(int i=1; i<=N; i++) vis[i] = false;
printf(bfs() ? "Yes\n" : "No\n");
}
return 0;
}