| ||||||||||
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 |
老大们,为什么有误啊?我检查了半天了都#include<iostream> using namespace std; int set[1010], x[1010], y[1010], num[1010],i,j,dis; bool flg[1010]; void make_set(int n) { for(i=1;i<=n;i++) { set[i]=i; num[i]=1; flag[i]=false; } } void make_xy(int i,int xx,int yy) { x[i]=xx; y[i]=yy; } int find_set(int xx) { int r=xx; while(set[r]!=r) { r=set[r]; } return r; } void merge_set(int a,int b) { if(a==b) return ; if(num[a]<=num[b]) { num[a]=b; num[b]+=num[a]; } else { num[b]=a; num[a]+=num[b]; } } bool connect_xy(int a,int b) { double d; d = (x[a]-x[b]) * (x[a]-x[b]) * 1.0 + (y[a]-y[b]) * (y[a]-y[b]); d = sqrt(d); if(d<=double(dis)) return true; else return false; } int main() { int xx,yy,n,var1,var2,var3,set1,set2; char ch; cin>>n; make_set(n); cin>>dis; for(i=1;i<=n;i++) { cin>>xx>>yy; make_xy(i,xx,yy); } while(cin>>ch) { if(ch=='O') { cin>>var1; flag[var1]=true; for(i=1;i<=n;i++) { if(connect_xy(var1,i)) merge_set(var1,i); } } else if(ch=='S') { cin>>var2>>var3; set1=find_set(var2); set2=find_set(var3); if(set1==set2) 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