排序+贪心
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bitset>
#include <vector>
#include <cstdlib>
using namespace std;
const int MAXNUM = 105;
struct Node
{
int begin,end;
Node(int a,int b):begin(a),end(b) {}
};
bool compare(const Node& n1,const Node& n2)
{
return n1.end < n2.end;
}
bitset<MAXNUM> bset;
int main()
{
//freopen("HDU2037.txt","r",stdin);
int n;
vector<Node> nodevec;
while(scanf("%d",&n)&&n)
{
nodevec.clear();
bset.reset();//all to zero
int i = 0,tmpa,tmpb;
while(i<n)
{
scanf("%d%d",&tmpa,&tmpb);
nodevec.push_back(Node(tmpa,tmpb));
i++;
}
sort(nodevec.begin(),nodevec.end(),compare);
bset.set(0);
int prev = 0;
for(int j = 1;j < nodevec.size();j++)
{
if(nodevec[j].begin >= nodevec[prev].end)
{
bset.set(j);
prev = j;
}
}
cout<<bset.count()<<endl;
}
return 0;
}