List2-이진탐색

광어회깍뚝썰기·2021년 7월 23일
0

swea-intermediate

목록 보기
7/51
def chk(target):
    l=1
    r=P
    cnt=0
    while True:
        c=(l+r)//2
        if c==target:
            break
        elif c>target:
            r=c
            cnt+=1
        else:
            l=c
            cnt+=1
    return cnt
            
    
for tc in range(1,int(input())+1):
    P,A,B = map(int,input().split())
    
    aa=chk(A)
    bb=chk(B)
    if aa<bb:
        res='A'
    elif aa==bb:
        res=0
    else:
        res='B'
    
    print(f'#{tc} {res}')  

텍스트

0개의 댓글

관련 채용 정보