| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一次A过 不废话贴代码#include <iostream> #include<stdio.h> #include<string.h> using namespace std; const int MAXN=1010 ; struct node { int x ; int y ; } ; node point[MAXN] ; int father[MAXN] ; bool flag[MAXN] ; int N,d ; void makeset() { for(int i=1 ;i<=N ;i++) father[i]=i ; } int findset(int x) { return (father[x]==x) ? x : father[x]=findset(father[x]) ; } void unionset(int a,int b) { int distance=(point[a].x-point[b].x)*(point[a].x-point[b].x)+(point[a].y-point[b].y)*(point[a].y -point[b].y) ; a=findset(a) ; b=findset(b) ; if(distance<=d*d && a!=b) { father[a]=b ; } } int main() { int i ; cin>>N>>d ; for(i=1 ;i<=N ;i++) cin>>point[i].x>>point[i].y ; char ch ; int temp ; makeset() ; memset(flag,false ,sizeof(flag)) ; while(cin>>ch) { if(ch=='O') { cin>>temp ; flag[temp]=true ; for(i=1 ;i<=N ;i++) if(flag[i]==true && i!=temp) unionset(i,temp) ; } else { int p,q ; cin>>p>>q ; if(findset(p)==findset(q)) cout<<"SUCCESS"<<endl ; else cout<<"FAIL"<<endl ; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator