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:你能不能去掉那些#ifdef DEBUG……看着头晕

Posted by lala_lala at 2006-03-22 22:59:31 on Problem 2236
In Reply To:你能不能去掉那些#ifdef DEBUG……看着头晕 Posted by:frkstyc at 2006-03-22 22:56:22
呵呵!!谢谢了
//#define DEBUG
#define MAXSIZE 1002
#define SQ(a) ((a)*(a))
#include<stdio.h>
#include<string.h>
#include<math.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 (temp>0) while(1);
	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));
	

	scanf("%d%d",&n,&d);

	for(i=0;i<n;i++){
	
		scanf("%d%d\n",&computer[i].x,&computer[i].y);

	}
	d*=d;

		while(gets(op)!=NULL){

			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:
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