ural 1203. Scientific conference

ural 1203. Scientific conference

#include < iostream >
using   namespace  std;

struct  arr{
    
int  x,y;
}a[
100001 ];
int  N,M;
int  f[ 30005 ];
int  cmp( const   void *  no1, const   void *  no2){
    
return  ( * (arr * )no1).x - ( * (arr * )no2).x;
}
int  main()
{
    scanf(
" %d " , & N);
    M
= 0 ;
    
for ( int  i = 1 ;i <= N; ++ i){
        scanf(
" %d%d " , & a[i].x, & a[i].y);
        
if (M < a[i].x) M = a[i].x;
        
if (M < a[i].y) M = a[i].y;
    }
    qsort(a
+ 1 ,N, sizeof (arr),cmp);
    f[M
+ 1 ] = 0 ;
    
for ( int  i = M;i >= 1 ; -- i){
        f[i]
= f[i + 1 ];
        
while (i == a[N].x){
            
if (f[i] < f[a[N].y + 1 ] + 1 )
                f[i]
= f[a[N].y + 1 ] + 1 ;
            N
-- ;
        }
    }
    printf(
" %d\n " ,f[ 1 ]);
    
return   0 ;
}




magio:
program ural1203;
const
  maxt
= 30000 ;
var
  s,f:array[
0 ..maxt]of word;
  n,i:longint;
  ts,te:word;
function max(a,b:word):word;
  begin
    
if  a > b then max: = else  max: = b;
  end;
begin
  read(n);
  
for  i: = 1  to n  do  begin
    read(ts,te);
    s[te]:
= max(s[te],ts);
  end;
  
for  i: = 2  to maxt  do
    
if  s[i] = 0  then
      f[i]:
= f[i - 1 ]
    
else
      f[i]:
= max(f[s[i] - 1 ] + 1 ,f[i - 1 ]);
  writeln(f[maxt]);
end.

你可能感兴趣的:(ural 1203. Scientific conference)