题目链接:http://poj.org/problem?id=2236
思路很简单,傻逼的我输出写成了FALL,然后遍历的时候for循环写错了,还好很快我就Debug出来了。
#include <stdio.h> struct Point { int x,y; } points[1010]; int father[1010]; bool vis[1010]= {false}; int Find_Set (int x) { if(x!=father[x]) father[x] = Find_Set(father[x]); return father[x]; } int main() { int N,d; scanf("%d%d",&N,&d); for(int i=1; i<=N; i++) father[i] = i; for(int i=1; i<=N; i++) scanf("%d%d",&points[i].x,&points[i].y); getchar(); char ch; while(scanf("%c",&ch)!=EOF) { getchar(); int n,m; if(ch=='O') { scanf("%d",&n); getchar(); vis[n] = true; for(int i=1; i<=N; i++) { if(i!=n&&vis[i]) { int tx = points[n].x - points[i].x; int ty = points[n].y - points[i].y; if(tx*tx+ty*ty<=d*d) { int fx = Find_Set(i); int fy = Find_Set(n); if(fx!=fy) father[fy] = fx; } } } } else { scanf("%d%d",&n,&m); getchar(); int fx,fy; fx = Find_Set(n); fy = Find_Set(m); if(fx!=fy) printf("FAIL "); else printf("SUCCESS "); } } return 0; }