oneju·2023년 4월 17일
0

Algorithm

목록 보기
5/11

큐 = 선입 선출 구조의 정렬 알고리즘

enque : 데이터를 넣는 ↔ deque : 원소를 빼는

front : 큐에서 가장 첫번째 값 a[0] ↔ rear : 큐에서 가장 마지막 값 a[-1]

요세푸스 문제

11866번: 요세푸스 문제 0

K번째를 계속해서 뽑아내는 요세푸스 문제를 해결해라

joseph = []
idx = 0
while lst:
    idx = (idx+K-1) % len(lst)
    num = lst.pop(idx)
    joseph.append(num)

3190번: 뱀

while True:
    y_i += y[idx]
    x_i += x[idx]

    if y_i in range(1,N+1) and x_i in range(1,N+1) and (x_i,y_i) not in length:
        time+=1
        if length and apple[x_i][y_i]==0:
            length.popleft()
            
        else:
            apple[x_i][y_i]=0
        
        length.append((x_i,y_i))
            
        if i < L and time == dir[i][0]:
            if dir[i][1] == "D":
                idx=(idx+1)%4
            else:
                idx=(idx-1)%4
            i+=1
    else:
        break

profile
hello, world

0개의 댓글