백준 1966 프린터 큐 - python

원준식·2021년 12월 5일
0

백준

목록 보기
1/10
from collections import deque
def f():
    ans=0
    N, M=map(int, input().split())
    n=deque(list(map(int, input().split())))
    n[M]+=0.1
    a=n[M]
    while True:
        if max(n) != a:
            if n[0] == max(n):
                ans+=1
                n.popleft()
                continue
            else:
                n.rotate(-1)
                continue
        else:
            if n[0] == a:
                ans+=1
                break
            elif n[0] == int(round(a-0.1)):
                ans+=1
                n.popleft()
                continue
            else:
                n.rotate(-1)
                continue
    return ans
t=int(input())
for _ in range(t):
    print(f())

M 번째 문서를 표시하기 위해 0.1을 더해서 풀었는데 계속 틀렸습니다.

알고 보니 4.1-0.1과 4는 다른 것이었습니다.

int(4.1-0.1)도 4가 아니고 3이었습니다.

그 부분에 round를 써주어 해결했습니다.

0개의 댓글