본문 바로가기

Algorithm89

[백준] 11286번 절대값 힙 예전에 풀었던 우선순위큐를 이용하면 금방 풀 수 있는 문제 import sys import heapq heap = [] size = 0 for _ in range(int(sys.stdin.readline())): N = int(sys.stdin.readline()) if N != 0: heapq.heappush(heap, (abs(N), N)) size += 1 else: if size == 0: print(0) else: print(heapq.heappop(heap)[1]) size -= 1 2020. 11. 26.
[백준] 1913번 달팽이 깡 구현 그 자체... BFS에서 길 찾기 했던거 약간 응용함.. 쓰읍.... 가독성을 위해 코드 길이가 길어졌는데.. 썩 효율적이지도 못한거 같다.. N = int(input()) findNum = int(input()) snail = [[0] * N for _ in range(N)] direction = [[1, 0], [0, 1], [-1, 0], [0, -1]] # 하 우 상 좌 diCurrent = 0 cX = 0 cY = 0 findX = 0 findY = 0 nN = N * N while True: if snail[cY][cX] == 0: snail[cY][cX] = nN nN -= 1 if nN == 0: break cY += direction[diCurrent][0] cX += direc.. 2020. 11. 26.
[백준] 1032번 명령 프롬프트 쉬운 문제.. import sys N = int(sys.stdin.readline()) dataList = [] for i in range(N): dataList.append(sys.stdin.readline().strip()) for i in range(len(dataList[0])): flag = 0 temp = dataList[0][i] for j in range(1, N): if dataList[j][i] != temp: print("?", end="") flag = 1 break if not flag: print(dataList[0][i], end="") 2020. 11. 25.
[백준] 1966번 프린터 큐 쉬운 문제.. import sys T = int(sys.stdin.readline()) for i in range(T): ans = 0 N, M = map(int, sys.stdin.readline().split()) tc = list(map(int, sys.stdin.readline().split())) tm = [0] * N tm[M] = 1 popData = max(tc) while True: tempM = tm.pop(0) tempC = tc.pop(0) if tempC == popData: ans += 1 if tempM == 1: break popData = max(tc) else: tc.append(tempC) tm.append(tempM) print(ans) 2020. 11. 25.