[NOIP 2017] 奶酪
[题目链接]
[算法]
直接搜索即可
注意使用long long
[代码]
#include<bits/stdc++.h> using namespace std; #define MAXN 1010 #define dist(x1,y1,z1,x2,y2,z2) sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)) struct info { long long x,y,z; } a[MAXN]; int i,T; long long n,h,r; bool ok; bool visited[MAXN]; inline void dfs(int now) { int i; if (h - a[now].z <= r) { ok = true; return; } visited[now] = true; for (i = 1; i <= n; i++) { if (!visited[i] && dist(a[now].x,a[now].y,a[now].z,a[i].x,a[i].y,a[i].z) <= 2 * r) dfs(i); } } int main() { scanf("%d",&T); while (T--) { scanf("%lld%lld%lld",&n,&h,&r); for (i = 1; i <= n; i++) scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].z); memset(visited,false,sizeof(visited)); ok = false; for (i = 1; i <= n; i++) { if (!visited[i] && a[i].z <= r) dfs(i); if (ok) break; } if (ok) printf("Yes\n"); else printf("No\n"); } return 0; }