Result: Accepted
Time: 4ms
Memory: 1756kB
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
typedef struct Book{
int len;
int wid;
}Book;
int main(){
int n,h,w,res,tmp,i;
Book b[1000]={{0,0}};
scanf("%d",&n);
res=0;
while(n--){
scanf("%d%d",&h,&w);
if(h>w){
swap(h,w);
}
if(b[0].len==0){
b[0].len=h;
b[0].wid=w;
res++;
}else{
for(i=0;b[i].len!=0;++i){
if(h<=b[i].len&&w<=b[i].wid){
b[i].len=h;
b[i].wid=w;
break;
}
}
if(b[i].len==0){
b[i].len=h;
b[i].wid=w;
res++;
}
}
}
printf("%d\n",res);
return 0;
}