ural 1078. Segments

ural 1078. Segments

#include < iostream >
using   namespace  std;

struct  arr{
    
int  x,y,c;
}a[
501 ];
int  N;
int  f[ 501 ];
int  p[ 501 ];
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;
}
int  main()
{
    scanf(
" %d " , & N);
    
for ( int  i = 0 ;i < N; ++ i){
        scanf(
" %d%d " , & a[i].x, & a[i].y);
        a[i].c
= i + 1 ;
    }
    qsort(a,N,
sizeof (arr),cmp);
    
int  Max = 0 ,pre;
    
for ( int  i = 0 ;i < N; ++ i){
        f[i]
= 1 ; p[i] = i;
        
for ( int  j = 0 ;j < i; ++ j)
            
if (a[i].x > a[j].x && a[j].y > a[i].y)
                
if (f[i] < f[j] + 1 ){
                    f[i]
= f[j] + 1 ;
                    p[i]
= j;
                }
        
if (f[i] > Max){
            Max
= f[i];
            pre
= i;
        }
        
else   if (f[i] == Max)
            
if (a[p[i]].c < a[pre].c)
                pre
= i;
    }
    printf(
" %d\n " ,Max);
    
while (pre != p[pre]){
        printf(
" %d  " ,a[pre].c);
        pre
= p[pre];
    }
    printf(
" %d\n " ,a[pre].c);
    
return   0 ;
}




你可能感兴趣的:(ural 1078. Segments)