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

help^^^^^^

Posted by ycyandkelly at 2005-04-29 15:02:12 on Problem 1828
运用两个二维数组,期中一个是存放具有最大值的猴子标号^

#include <iostream.h>

int** search(int **array, int n)
{
	int ** p;
	p= new int*[n];
	for(int i=0; i<n; i++)
		p[i]=new int[2];

	for(i=0; i<n; i++)
		for(int j=0; j<2; j++)
			p[i][j]=1;

	for(int k=0; k<n; ++k)
		for(int ii=0; ii<n; ++ii)
		   if(array[k][0]<array[ii][0]) 
		   {
			   p[k][0]=0;
			   break;
		   }
		   
    for(int j=0; j<n; ++j)
		for(int jj=0; jj<n; ++jj)
		   if(array[j][1]<array[jj][1])
		   {
			   p[j][1]=0;
			   break;
		   }
    return p;
}

int compare(int **array, int n)
{
	int ** p;
	int max=0;
	p=search(array, n);

	for(int i=0; i<n; ++i)
		if(p[i][0]&&p[i][1]) max++;
	if(max) return max;
	
	for(int j=0; j<n; j++)
		if(p[j][0]||p[j][1]) max++;
		if(max!=n) return max;
		return 0;
}

void main()
{
	int n, **array;
	while(1)
	{
		cin>>n;
		if(n==0) break;
	    array= new int*[n];
		for(int i=0; i<n; i++)
		   array[i]=new int[2];

	    for(i=0; i<n; i++)
		   for(int j=0; j<2; j++)
		       cin>>array[i][j];
	
		   cout<<compare(array, n)<<endl;
	}
}

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