#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int n;
struct a{
int x,y;
};
bool operator < (const a & c,const a& b){
if(c.x == b.x)
return c.y < b.y;
return c.x < b.x;
}
a monkey[50010];
int main(){
int ans = 0;
while(scanf("%d",&n)&&n){
ans = 0;
memset(monkey,0,sizeof(monkey));
for(int i = 1; i <= n; ++i){
scanf("%d%d",&monkey[i].x,&monkey[i].y);
}
sort(monkey+1,monkey+n+1);
if(n == 1){
printf("1\n");
continue;
}
else{
ans = 1; //最后一点一定是
int j = n - 1;
int tempy = monkey[n].y;
while(j > 0){
if(monkey[j].y >tempy){
++ans;
tempy = monkey[j].y;
}
--j;
}
printf("%d\n",ans);
}
}
return 0;
}
主要算法:
排序;
因为是按先x后y排序,所以从后向前找坐标(前面的点x一定小于后面,
所以只有前面的点的y坐标比后面的大时,才可以++ans),同时这样的查找方法保证了tempy是递增的~
即只要比tempy大,那么比后面所有点的y都大~
注:g++编译器中对小于号的重载要写在类的外面~否则会ce
原因还不太清楚~求指点