| ||||||||||
| 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 | |||||||||
这个题目使用并插集做吗?怎么总是WA ! 有人愿意帮看下我的程序吗? 谢谢//#define DEBUG
#define MAXSIZE 1002
#define SQ(a) ((a)*(a))
#include<stdio.h>
#include<string.h>
struct coor{
long x;
long y;
};
struct coor computer[MAXSIZE];
int n,sc[MAXSIZE];
short flag[MAXSIZE];
long d;
int u(int a,int b){
int temp=sc[a]+sc[b];
if (sc[a]<sc[b]){
sc[b]=temp;
sc[a]=b;
return b;
}
sc[a]=temp;
sc[b]=a;
return a;
}
int find(int p){
while(sc[p]>0) p=sc[p];
return p;
}
void test(int x,int y){
x=find(x);
y=find(y);
if ((x==y))
printf("SUCCESS\n");
else
printf("FAIL\n");
}
void rep(int p){
int s=find(p);
int i,k;
flag[p]=1;
for(i=0;i<n;i++){
if (flag[i]!=0)
if ((SQ(computer[i].x-computer[p].x)+SQ(computer[i].y-computer[p].y))<=d){
k=find(i);
if (k!=s)
s=u(s,k);
}
}
}
int main(){
int i,p,x,y;
char op[10];
memset(sc,-1,sizeof(sc));
#ifdef DEBUG
FILE *fp=fopen("in.dat","r");
fscanf(fp,"%d%d",&n,&d);
#else
scanf("%d%d",&n,&d);
#endif
for(i=0;i<n;i++){
#ifdef DEBUG
fscanf(fp,"%d%d\n",&computer[i].x,&computer[i].y);
#else
scanf("%d%d",&computer[i].x,&computer[i].y);
#endif
}
d*=d;
#ifdef DEBUG
while(fgets(op,10,fp)!=NULL){
#else
while(fgets(op,10,stdin)!=NULL){
#endif
if (op[0]=='O'){
sscanf(op+1,"%d",&p);
rep(p-1);
}else{
sscanf(op+1,"%d%d",&x,&y);
test(x-1,y-1);
}
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator