提交时间:2024-03-30 14:32:20

运行 ID: 140346

#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cstdlib> #include<cmath> using namespace std; const int N=100005; int n,m,t,ans=1; struct node{ int x; int y; }a[N]; node way[N]; int dd=1; bool cmp(node p,node q){ if(p.x==q.x) return p.y<q.y; else return p.x<q.x; } bool pd(int p,int q){ for(int i=1;i<=dd;i++){ if(p>=way[i].x && q>=way[i].y){ way[i].x=p; way[i].y=q; return 1; } } return 0; } int main(){ scanf("%d %d %d",&n,&m,&t); if(n==1 || m==1) { printf("1"); return 0; } for(int i=1;i<=t;i++) scanf("%d %d",&a[i].x,&a[i].y); sort(a+1,a+t+1,cmp); for(int i=1;i<=t;i++){ bool gf=pd(a[i].x,a[i].y); if(gf==0){ way[++dd].x=a[i].x; way[dd].y=a[i].y; } } cout<<dd; return 0; }//bz