본문 바로가기
320x100

PS84

[CLASS 3]백준 11286번 - 절댓값 힙 11286번 : 절댓값 힙 직접 구현하지는 않고 힙큐 모듈을 사용했다. 내 코드: # dawitblog.tistory.com from sys import stdin import heapq input = stdin.readline plusHeap = [] minusHeap = [] for _ in range(int(input())): req = int(input()) if req: if req > 0: heapq.heappush(plusHeap,req) else: heapq.heappush(minusHeap,-req) else: if not plusHeap and not minusHeap: print(0) elif not plusHeap: print(-heapq.heappop(minusHeap)) elif.. 2021. 2. 13.
[CLASS 3]백준 9205번, 11047번 9205번 : 맥주 마시먼서 걸어가기 맥주를 마시면서 페스티벌에 걸어간다는 이야기를 가지고 있는... 그런 문제이다. 그래프 탐색 dfs혹은 bfs로 풀면 된다. 먼저 bfs로 푼다면 다음과 같다. 내 코드(BFS): import sys from collections import deque input = sys.stdin.readline for _ in range(int(input())): convNum = int(input()) home = tuple(map(int,input().split())) points = [] for _ in range(convNum): points.append(tuple(map(int,input().split()))) dest = tuple(map(int,input().spl.. 2021. 2. 12.
[CLASS 3]백준 - 7576번, 7569번 - 토마토 7576번 : 토마토 심심하다 싶으면 나오는 bfs문제이다. bfs말고 dfs문제좀 풀어보고 싶다. 이전까지 내가 풀어온 bfs문제와 좀 다른게 있다면 시작점이 정해져 있지 않고 퍼져 있다는 점이다. 내 코드(정답이지만 채점오류 같음): # dawitblog.tistory.com from sys import stdin from collections import deque dx = [0,0,1,-1] dy = [1,-1,0,0] def tomato_bfs(box,queue): global changed while queue: tx,ty = queue.popleft() for i in range(4): x = tx + dx[i] y = ty + dy[i] if 0 2021. 2. 11.
[CLASS 3]백준 6064번 - 카잉 달력 6064번 : 카잉 달력 잉카 문명에 관한 이야기와 달력 이야기가 나와 있다. 아마 이게 2012년에 지구가 멸명한다는 이야기의 근원인가..? 그랬던 것 같다. 그것과 별개로 이 문제는 나에게 너무 어려웠다.. 결국 풀이를 봤는데 풀이를 보니 이해는 되는데 이걸 어떻게 떠올리지? 같은 느낌이다. import sys input = sys.stdin.readline for _ in range(int(input())): m,n,x,y = map(int,input().split()) while x (m*n): print(-1) 일단 생각해보면 원하는 게 라고 하고 이때가 k번째라고 할때, 앞자리인 x를 맞추기 위해 k는 m으로 나누었을 때 나머지가 x이어야 한다. 예를 들어 x가 3이고 m이 10이라면 k는 적.. 2021. 2. 11.