赞
踩
题意:
一个长宽无限的立方体中有一些空洞,相交或者相接的空洞可以互相到达,跟立方体下表面相交或相切的空洞可以从下表面到达,上表面同理,问是否可以从下表面到达上表面。
题解:
建图之后floodfill,注意建图可能爆long long或者double的精度问题。
代码:
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- #include <algorithm>
- #include <cstdlib>
- #include <ctime>
-
- using namespace std;
-
- const int MAXN = 1005;
- const int MAXM = 1002005;
-
- struct Edge
- {
- int to;
- int next;
- }edge[MAXM << 1];
-
- int T,n,id;
- int first[MAXN];
-
- long long r,h;
- long long x[MAXN];
- long long y[MAXN];
- long long z[MAXN];
-
- bool mark[MAXN];
-
- void addE(int u,int v)
- {
- edge[++id] = (Edge){v,first[u]};
- first[u] = id;
- }
-
- bool dfs(int now)
- {
- if (now == n + 1)
- return true;
- if (mark[now])
- return false;
- mark[now] = true;
- for (int i = first[now];i;i = edge[i].next)
- if (dfs(edge[i].to))
- return true;
- return false;
- }
-
- int main()
- {
- freopen("cheese.in","r",stdin);
- freopen("cheese.out","w",stdout);
- ios::sync_with_stdio(false);
- cin >> T;
- while (T--)
- {
- memset(first,0,sizeof(first));
- memset(mark,0,sizeof(mark));
- id = 0;
- cin >> n >> h >> r;
- for (int i = 1;i <= n;i++)
- {
- cin >> x[i] >> y[i] >> z[i];
- if (z[i] < 0)
- while(1){}
- if (z[i] <= r)
- addE(0,i),addE(i,0);
- if (h - z[i] <= r)
- addE(n + 1,i),addE(i,n + 1);
- }
- r *= 2;
- for (int i = 1;i <= n;i++)
- for (int j = 1;j <= n;j++)
- if (i != j && (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) <= r * r - (z[i] - z[j]) * (z[i] - z[j]))
- addE(i,j),addE(j,i);
- cout << (dfs(0) ? "Yes" : "No") << endl;
- }
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。