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

为什么老是WR呀 哪位大牛指点一下!

Posted by hustest03 at 2006-02-24 15:12:19 on Problem 2349
#include<stdio.h>
#include<math.h>
void main()
{
   int size,S,P,i,j,k;
   int X[500],Y[500],outpost[500];
   int flag[500];
   float dist[500][500],result[500],temp;
   scanf("%d",&size);
   while(size>0)
   {
       scanf("%d %d",&S,&P);
	   for(i=0;i<P;i++)
		   scanf("%d %d",&X[i],&Y[i]);
	   for(i=0;i<P;i++)
	   
	      for(j=0;j<=i;j++)
		  {
			  dist[i][j]=0;
		      dist[j][i]=0;
		  }
	   for(i=0;i<P;i++)
	   {
		  for(j=0;j<=i;j++) 
		  {
			  if(i==j)
			     dist[i][j]=0;
	          else
			  {
				  dist[i][j]=sqrt( (X[i]-X[j])*(X[i]-X[j]) + (Y[i]-Y[j])*(Y[i]-Y[j]) );
			      dist[j][i]=dist[i][j];
			  }
		  }
		  flag[i]=0;     
	   }
	   outpost[0]=0;
	   result[0]=0;
	   flag[0]=1;
	   k=1;
	   do
	   {
     	   for(j=0,result[k]=30000;j<k;j++)
		     for(i=0;i<P;i++)
		     if(flag[i]==0 && result[k]>dist[j][i] )
			 {
			     result[k]=dist[j][i];
		         outpost[k]=i;
			 }
		   flag[outpost[k]]=1;
		   k++;
         
   	   }while(k<P);
	   for(i=1;i<P-1;i++)
		   for(j=i+1;j<P;j++)
			   if(result[i]<result[j])
			   {
				   temp=result[i];
			       result[i]=result[j];
				   result[j]=temp;
			   }
    printf("%.2f\n",result[S]);
      //for(i=1;i<P;i++)
        //  printf("%.2f\n",result[i]);    
	  size--;
   }
}

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