ural 1064. Binary Search

ural 1064. Binary Search

#include < iostream >
using   namespace  std;

int  N;
int  ai,l;
int  n,x[ 10100 ],y[ 10100 ];
int  bsearch( int  LN){
    
int  p,q,i,L = 0 ;
    p
= 0 ; q = LN - 1 ;
    
while (p <= q){
        i
= (p + q) / 2 ;
        
++ L;
        
if (i == ai)  return  L;
        
if (ai < i) q = i - 1 ;
        
else  p = i + 1 ;
    }
    
return   0 ;
}
int  main()
{
    scanf(
" %d%d " , & ai, & l);
    N
= 1 ; n = 0 ;
    
int  ax = 0 ,ay = 0 ;
    
do {
        
int  k = bsearch(N);
        
if (k != l){
            
if (ax){
                x[
++ n] = ax; y[n] = ay;
            }
            ax
= ay = 0 ;
        }
        
else {
            
if (ax) ay = N;
            
else  ax = ay = N;
        }
        N
++ ;
    }
while (N <= 10000 );
    
if (ax){
        x[
++ n] = ax; y[n] = ay;
    }
    printf(
" %d\n " ,n);
    
for ( int  i = 1 ;i <= n; ++ i)
        printf(
" %d %d\n " ,x[i],y[i]);
    
return   0 ;
}




你可能感兴趣的:(ural 1064. Binary Search)