개발노트(150)
-
(큐, 덱) 프린터 큐
이 문제의 저작권은 BAEKJOON에 있습니다. https://www.acmicpc.net/problem/1966 문제는 위 링크에서 확인할 수 있습니다. #https://www.acmicpc.net/problem/1966 #프린터 큐 import sys from collections import deque TC = int(input()) for _ in range(TC): count = 1 #N은 문서의 수 M은 몇 번째로 인쇄되었는지 궁금한 문서 N, M = map(int, input().split()) q = list(map(int, input().split())) q = deque(q) pointer = [i for i in range(N)] pointer = deque(pointer) while..
2020.03.03 -
(큐, 덱) 요세푸스 문제 0
이 문제의 저작권은 BAEKJOON에 있습니다. https://www.acmicpc.net/problem/11866 문제는 위 링크에서 확인할 수 있습니다. #https://www.acmicpc.net/problem/11866 #요세푸스 문제 0 import sys from collections import deque N, K = map(int,input().split()) A = [i for i in range(1, N+1)] q = deque(A) temp = [] while 1: if len(q) == 0: print(f'') break for _ in range(K-1): q.rotate(-1) get_pop = q.popleft() temp.append(get_pop) 총 N명의 사람이 있고 K..
2020.03.03 -
(큐, 덱) 카드2
이 문제의 저작권은 BAEKJOON에 있습니다. https://www.acmicpc.net/problem/2164 문제는 위 링크에서 확인할 수 있습니다. #https://www.acmicpc.net/problem/2164 #카드2 import sys from collections import deque N = int(sys.stdin.readline().strip()) A = [i for i in range(N, 0, -1)] q = deque(A) check = 0 while 1: if len(q) == 1: print(q[0]) break if check == 0: #0이면 버리기 q.pop() else: #1이면 제일 아래로 옮기기 q.rotate(1) #버리기와 옮기기 번갈아서 하기위해 chec..
2020.03.03 -
(큐, 덱) 큐2
이 문제의 저작권은 BAEKJOON에 있습니다. https://www.acmicpc.net/problem/18258 문제는 위 링크에서 확인할 수 있습니다. #https://www.acmicpc.net/problem/18258 #큐 2 import sys from collections import deque def cmd(A): if A[0] == 'push': q.append(A[1]) elif A[0] == 'pop': try: value = q.popleft() print(value) except: print(-1) elif A[0] == 'size': print(len(q)) elif A[0] == 'empty': if len(q) > 0: print(0) else: print(1) elif A[..
2020.03.03 -
(스택) 스택 수열
이 문제의 저작권은 BAEKJOON에 있습니다. https://www.acmicpc.net/problem/1874 문제는 위 링크에서 확인할 수 있습니다. #https://www.acmicpc.net/problem/1874 r = int(input()) stack =[] chk = [] result = [] # 기본 세팅 for i in range(r) : chk.append(int(input())) idx = 0 for i in range(1,r+1) : stack.append(i) result.append("+") while idx < r and len(stack) != 0 and chk[idx] == stack[-1] : stack.pop() result.append("-") idx = idx + ..
2020.03.03 -
(스택) 균형잡힌 세상
이 문제의 저작권은 BAEKJOON에 있습니다. https://www.acmicpc.net/problem/4949 문제는 위 링크에서 확인할 수 있습니다. S_cnt = 0 while True: S = input() if S == '.': break temp = [] err = 0 S_size = len(S) for i in range(0, S_size - 1): if S[i] is '(' or S[i] is '[': temp.append(S[i]) elif S[i] is ')' or S[i] is ']': try: if S[i] is ')' and temp[-1] is '(': temp.pop() elif S[i] is ']' and temp[-1] is '[': temp.pop() else: err ..
2020.02.28