sort函数用法:
#include<algorithm>
using namespace std;
sort(a,a+len;cmp) //a-->数组名, len-->数组长度
C/C++:
1 #include<stdio.h> 2 #include<algorithm> 3 using namespace std; 4 typedef struct 5 { 6 int x; 7 int y; 8 }pi; 9 pi p[5002]; 10 11 int number(int n) 12 { 13 int t, cnt = 0; 14 for(int i = 0; i < n; ++i) 15 { 16 if(p[i].y) 17 { 18 ++cnt; 19 t = p[i].y; 20 p[i].y = 0; 21 for(int j = i + 1; j < n ;++j) 22 { 23 if(p[j].y >= t) 24 { 25 t = p[j].y; 26 p[j].y= 0; 27 } 28 } 29 } 30 } 31 return cnt; 32 } 33 34 int cmp( pi a,pi b) 35 { 36 if(a.x>b.x) 37 return 0; 38 if(a.x==b.x) 39 return a.y<b.y; 40 return 1; 41 } 42 int main() 43 { 44 // freopen("250.txt","r",stdin); 45 int t,n,i; 46 int sum=1; 47 scanf("%d",&t); 48 while(t--) 49 { 50 sum=1; 51 scanf("%d",&n); 52 for(i=0;i<n;i++) 53 scanf("%d%d",&p[i].x,&p[i].y); 54 sort(p,p+n,cmp); 55 // for(i=0;i<n;i++) 56 // printf("%d %d ",p[i].x,p[i].y); 57 58 printf("%d ",number(n)); 59 } 60 return 0; 61 }
java: