排个序,模拟下就好了,水题一个
/* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #define INF 1E9 using namespace std; struct node { int x,y; }; node o[50001]; bool cmp(node a,node b) { if(a.y!=b.y) return a.y>b.y; return a.x>b.x; } int main() { int n,i; while(~scanf("%d",&n)&&n) { for(i=0;i<n;i++) scanf("%d%d",&o[i].x,&o[i].y); sort(o,o+n,cmp); int ans=1; int x=o[0].x; for(i=0;i<n;i++) { if(o[i].x>x) { x=o[i].x; ans++; } } printf("%d\n",ans); } }