xfstart07
Get busy living or get busy dying

#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.

posted on 2009-06-19 15:50 xfstart07 阅读(256) 评论(0)  编辑 收藏 引用 所属分类: 代码库

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理