알고리즘(8)
-
미로 탐색
from collections import deque from collections import deque n,m = map(int,input().split()) graph = [list(map(int,input())) for _ in range(n)] visited = [[False]*m for _ in range(n)] dx = [-1,1,0,0] dy = [0,0,-1,1] def bfs(x,y): queue = deque() queue.append((x,y)) while queue: x,y = queue.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0
2024.02.06 -
백준 10828번 스택
굉장히 기본적인 문제라고 생각한다. append, pop,len(list),list[-1]을 활용해서 문제를 풀 계획이다. 다음 코드를 보면서 참고하면 좋을 것 같다. import sys input = sys.stdin.readline n =int(input()) stack = [] for _ in range(n): stack_word = input().split() if stack_word[0] =='push': stack.append(int(stack_word[1])) elif stack_word[0]=='pop': if len(stack)==0: print(-1) else: print(stack.pop()) elif stack_word[0]=='size': print(len(stack)) elif ..
2024.01.25