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

恳请哪个个牛人帮我看下啊!不知为啥总是WA!

Posted by kaztc at 2009-02-14 11:56:35 on Problem 1065
#include <iostream>

using namespace std;

int ok ( int [] , int [] , int ) ;
void sort ( int [] , int [] , int ) ;

int main()
{
	int n ;
	cin >> n;

	int *ans ;
	ans = new int [n] ;

	for ( int i  = 0 ; i < n ; i ++ ){
		int k ; 
		cin >> k ;

		int * l , * w ;

		l = new int [k] ;
		w = new int [k] ;

		for ( int j = 0 ; j < k ; j ++ )
			cin >> l[j] >> w[j] ;

		sort (l , w , k) ;

		ans[i] = ok ( l , w , k ) ;

	}

	for ( int ii = 0 ; ii < n ; ii ++ )
		cout << ans[ii] << endl;

	return 0 ;

}


int ok ( int l[] , int w[] , int k ) 
{
	int  * visited ;
	visited = new int [k] ;
	
	for ( int j = 0 ; j < k ; j ++ )
		visited[j] = 0 ;
	
	int kk = 0 ;
	
	for ( int i = 0 ; i < k ; i ++ ){
		if ( visited[i] == 0 ){
			kk ++ ;
			for ( int j = i + 1 ; j < k ; j ++ ){
				if ( l[j] > l[i] && w[j] > w[i] )
					visited[j] = 1 ;
			}
		}
	}
	
	return kk ;
}

void sort ( int l[] , int w[] , int k )
{
	for ( int i = 0 ; i < k - 1 ; i ++ ){
		for ( int j = i + 1 ; j < k ; j ++ ){
			if ( l[i] > l[j] ){
				int lchange = l[i] , wchange = w[i] ;
				l[i] = l[j] ;  w[i] = w[j] ;
				l[j] = lchange ;  w[j] = wchange ;
			}
		}
	}

}

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