hdu 2037

View Code
Problem : 2037 ( 今年暑假不AC )     Judge Status : Accepted
RunId : 5746559    Language : C++    Author : billforum
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
#include <iostream>
 #include <algorithm>
 #include <stdio.h>

 using namespace std;
 
 const int N=105;
 
 struct node
 {
     int s,f;
 };
 node nd[N];
 
 bool cmp(node x,node y)
 {
     if(x.f==y.f) return (x.s<y.s);
     else return(x.f<y.f);
 }
 int main()
 {
    int n,num,f;
    while(scanf("%d",&n)==1)
    {
        if(n==0) break;
        num=0;
        f=0;
        for(int i=0;i<n;i++)
            scanf("%d %d",&nd[i].s,&nd[i].f);
        sort(nd,nd+n,cmp);    
        for(int i=0;i<n;i++)
        {
            if(nd[i].s>=f)
            {
                num++;
                f=nd[i].f;
            }
        }
        cout<<num<<endl;
    }
         return 0;
 }

  

posted @ 2012-04-10 19:51  wuzhibin  阅读(308)  评论(0)    收藏  举报