http://acm.hdu.edu.cn/showproblem.php?pid=2037

    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. int n;
    4. const int maxn = 1000;
    5. struct timenode{
    6. int s;
    7. int e;
    8. };
    9. bool cmp(timenode a,timenode b){
    10. return a.e < b.e;
    11. }
    12. timenode t[maxn];
    13. int main(){
    14. while(~scanf("%d",&n)&&n){
    15. for(int i=0;i<n;i++){
    16. cin >> t[i].s >> t[i].e;
    17. }
    18. int ans = 0,lastend = -1;
    19. sort(t,t+n,cmp);
    20. for(int i=0;i<n;i++){
    21. if(t[i].s>=lastend){
    22. ans++;
    23. lastend = t[i].e;
    24. }
    25. }
    26. cout << ans << endl;
    27. }
    28. return 0;
    29. }