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 xuguangshengqq at 2007-07-24 18:34:11 on Problem 2485
#include <stdio.h>
#include <memory.h>
/*
Sample Input


1

3
0 990 692
990 0 179
692 179 0

Sample Output
692
*/
struct node
{
int x,y,v;
};


int t,n;
node a[125001];
int b[501];
int  split (node A[],int low,int high);
void quicksort(node A[],int low,int high);
int work();
bool test(int x,int y);
void change(int x,int y);
int min(const int &x,const int &y);



void main()
{
    int i,j,k,temp,ct;
     scanf("%d",&t);
	for(k=1;k<=t;k++)
	{   
		
		scanf("%d",&n);
		ct = 1;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
			 scanf("%d",&temp);
			 
			 if(i<j)
			 {
				 a[ct].v = temp;
				 a[ct].x = i;
				 a[ct].y = j;
				 ct++;
			 }
		}/*readIn() is over*/
        
		
	}
		int result = work();
		printf("%d\n\n",result);

}
}




int   work()
{    //printf("I am working!\n");
     int i;
    
	 
     int len = (n-1)*n/2;
	 quicksort(a,1,len);
	 //for(i=1;i<=len;i++)printf("%d  ",a[i].v);
	 
	 for(i=1;i<=n;i++)
	 {
	  b[i] = i;
	 }
	 
	 b[a[1].x] = b[a[1].y] = min(a[1].x,a[1].y);
	 int ct = 1;
	 i = 1;
     for(i=2;i<=len;i++)
	 {
	   if(test(a[i].x,a[i].y))
	   {
	   change(a[i].x,a[i].y);
	   ct++;
	   }
	   if(ct==n-1)break;
	 
	 }
	//printf("a[%d] = %d\n",i,a[i].v);
	 //if(len==1) i = 1;
     return a[i].v;

} 


void quicksort(node A[],int low,int high)
{
	 //printf("I am sorting!\n");

   int k;
   if(low<high)
   { 
       k = split(A,low,high);
	   quicksort(A,low,k-1);
	   quicksort(A,k+1,high);
   } 

}

bool test(int x,int y)
{
  if(b[x]==b[y])return false;
  else return true;

}

void change(int x,int y)
{
	int mini = x<y?x:y;
	int maxi = x>y?x:y;
	int i = 1;
	for(i=1;i<=n;i++)
	{
		if(b[i]==maxi)
		b[i] = mini;
	}
}


int min(const int &x,const int &y)
{return x<y?x:y;}

int split(node A[],int low,int high)
{
	int k,i = low,temp;
	int x = A[low].v;
	for(k = low+1;k<=high;k++)
	{
	  if(A[k].v <= x)
	  {
	   i++;
	   if(i!=k)
	   {
	       
		    temp = a[i].v;
			a[i].v = a[k].v;
			a[k].v = temp;
			temp = a[i].x;
			a[i].x = a[k].x;
			a[k].x = temp;
			temp = a[i].y;
			a[i].y = a[k].y;
			a[k].y = temp;   
	   }
	  }
	}
	        temp = a[i].v;
			a[i].v = a[low].v;
			a[low].v = temp;
			temp = a[i].x;
			a[i].x = a[low].x;
			a[low].x = temp;
			temp = a[i].y;
			a[i].y = a[low].y;
			a[low].y = temp;  
			return i;
}



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