Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
恳请哪个个牛人帮我看下啊!不知为啥总是WA!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator