Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请问我的代码为什么老师RE啊

Posted by Nabokov at 2007-05-01 12:55:12 on Problem 2236
#include<stdio.h>
#include<string.h>
#include<math.h>
#define maxn 1005
#define ee 1e-10
int father[maxn];
__int8 mark[maxn];
int rank[maxn];
int site[maxn][2];

int findset(int u)
{return (father[u]==0)?u:(father[u]=findset(father[u]));
}

void merge(int i,int j)
{i=findset(i);
 j=findset(j);
 if(rank[i]>rank[j]) father[j]=i;
 else if(rank[i]<rank[j]) father[i]=j;
 else  {
  father[i]=j;
  ++rank[j];
 }
}
double dis(int a[2],int b[2])
{return sqrt((a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1]));
}
int zero(double d)
{if(fabs(d)<ee) return 0;
return (d>0)?1:-1;
}
int main()
{int n,d;
 int x,y; 
 int i,j;
 int p,q;
 char ch;
 memset(father,0,sizeof(father));
 memset(mark,0,sizeof(mark));
 memset(rank,0,sizeof(rank));
 
// freopen("file.in","r",stdin);

 scanf("%d%d",&n,&d);
 for(i=1;i<=n;i++)
	 scanf("%d%d",&site[i][0],&site[i][1]);
 while(getchar(),scanf("%c",&ch)!=EOF)
 {if(ch=='O'){
  	 scanf("%d",&p);
	 mark[p]=1;
	 for(j=1;j<=n;j++)
		 if(p!=j && mark[j])
			 if(zero(dis(site[p],site[j])-d)<=0){
				 merge(p,j);
			 }
 }
 if(ch=='S'){
     scanf("%d%d",&p,&q);
	 if(findset(p)==findset(q)) printf("SUCCESS\n");
	 else printf("FAIL\n");
 }
 }
 return 0;
}





         



 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator