零件分组

零件分组

#include < iostream >
using   namespace  std;

struct  arr{
    
int  x,y;
}a[
1000 ];
int  n;
int  f[ 1000 ];
int  cmp( const   void *  no1, const   void *  no2){
    arr 
* nox = (arr * )no1, * noy = (arr * )no2;
    
if (nox -> x != noy -> x)  return  nox -> x - noy -> x;
    
else   return  nox -> y - noy -> y;
}
int  main()
{
    freopen(
" stick.in " , " r " ,stdin);
    freopen(
" stick.out " , " w " ,stdout);
    scanf(
" %d " , & n);
    
for ( int  i = 0 ;i < n; ++ i) 
        scanf(
" %d%d " , & a[i].x, & a[i].y);
    qsort(a,n,
sizeof (arr),cmp);
    
int  MAX = 0 ;
    
for ( int  i = 0 ;i < n; ++ i){
        f[i]
= 1 ;
        
for ( int  j = i - 1 ;j >= 0 ; -- j)
            
if (a[i].y < a[j].y && f[i] < f[j] + 1 )
                f[i]
= f[j] + 1 ;
        
if (f[i] > MAX) MAX = f[i];
    }
    printf(
" %d\n " ,MAX);
    
return   0 ;
}




你可能感兴趣的:(零件分组)