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

改三个地方!

Posted by frkstyc at 2006-03-22 23:01:09 on Problem 2236
In Reply To:这个题目使用并插集做吗?怎么总是WA ! 有人愿意帮看下我的程序吗? 谢谢 Posted by:lala_lala at 2006-03-22 22:40:18
> //#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];
               ~~~~~~~~>=0.....
> 	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];
                 ~~100吧,不用那么省的
> 	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);
                             ~~\n怎么没有了……
> #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:
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