排序的应用,地址:http://acm.pku.edu.cn/JudgeOnline/problem?id=1828
#include "stdio.h"
int num[50005][2];
int qu[50005];
int judge(int a,int b)
{
    
int ans=0;
    
int i;
    
for(i=0;i<2;i++)
    
{
        
if(num[qu[a]][i]>num[qu[b]][i]){ans=1;break;}
        
if(num[qu[a]][i]<num[qu[b]][i]){ans=-1;break;}
    }

    
return ans;
}

void swap(int a,int b)
{
    
int t;
    t
=qu[a];
    qu[a]
=qu[b];
    qu[b]
=t;
}

int partion(int low,int high,int p)
{
    
while(low<=high)
    
{
        
if(low<p)
        
{
            
if(judge(low,p)>0){swap(low,p);p=low;}
            low
++;
        }

        
else
        
{
            
if(high>p)
            
{
                
if(judge(high,p)<0){swap(high,p);p=high;}
            }

            high
--;
        }

    }

    
return p;
}

void qsort(int left,int right)
{
    
int middle;
    
if(left<right)
    
{
        middle
=(left+right)/2;
        middle
=partion(left,right,middle);
        qsort(left,middle
-1);
        qsort(middle
+1,right);
    }

}

int main()
{
    
int n,i;
    
int count,last;
    
while(1)
    
{
        scanf(
"%d",&n);
        
if(n==0)break;
        
for(i=0;i<n;i++){scanf("%d%d",&num[i][0],&num[i][1]);qu[i]=i;}
        qsort(
0,n-1);
        count
=1;last=n-1;
        
for(i=n-2;i>=0;i--)
        
{
            
if(num[qu[i]][0]!=num[qu[i+1]][0])
            
{
                
if(num[qu[i]][1]>num[qu[last]][1])
                
{
                    count
++;
                    last
=i;
                }

            }

        }

        printf(
"%d\n",count);
    }

    
return 0;
}