본문 바로가기
320x100

Blog189

[CLASS 4]백준 9935번 - 문자열 폭발 9935번 - 문자열 폭발 솔직히 상당히 쉬운 문제인데 너무 어렵게 접근한 감이 없지않아 있다. 먼저 스택을 사용해야 한다는 것만 떠올릴 수 있다면 쉽게 풀 수 있었다. 내 코드: # dawitblog.tistory.com/159 string, explosion = input(),input() explosion_length = len(explosion) str_stack,explosion_stack = [],[] str_pointer = -1 # 폭발 문자열이 하나의 문자일 경우 if len(explosion) == 1: string = string.replace(explosion,'') print(string if string else 'FRULA') exit() idx_dict = {} for i i.. 2021. 5. 31.
[CLASS 4]백준 2638번 - 치즈 2638번 : 치즈 그림을 보자마자 BFS 문제라는것을 유추할 수 있다. 처음에 문제를 대충 읽어서 가장자리에는 치즈가 없다는 사실을 모르고 풀어서 코드가 좀더 길고 시간복잡도도 컸는데, 후에 깨닫고 고쳐서 괜찮은 코드가 된 것 같다. 내 코드: # dawitblog.tistory.com/158 from sys import stdin from collections import deque input = stdin.readline R,C = map(int,input().split()) mat = [] for _ in range(R): mat.append(list(map(int,input().split()))) time = 0 moves = [(0,1),(0,-1),(1,0),(-1,0)] def bfs(st.. 2021. 5. 20.
[CLASS 4]백준 2448번 - 별 찍기 2448번 : 별 찍기 재미도 없고... 머리만 아픈 별찍기... 분류에는 재귀라고 나와있는데 재귀는 쓰지도 않았다. 내 코드: from math import log s = [' * ', ' * * ', '***** '] def star(shift): c = len(s) for i in range(c): s.append(s[i] + s[i]) s[i] = " " * shift + s[i] + " " * shift n = int(input()) k = int(log(n // 3, 2)) for i in range(k): star(int(pow(2, i))) for i in range(n): print(s[i]) 2021. 5. 13.
[CLASS 4]백준 2206번 - 벽 부수고 이동하기 2206번 : 벽 부수고 이동하기 말 그대로 벽을 부수며 이동할 수 있는 문제이다. 벽은 단 한번만 부술 수 있다. BFS를 통해 탐색하면서 벽을 부쉈는지 안 부쉈는지에 따라 분기하면 된다. 내 코드: # dawitblog.tistory.com/156 from sys import stdin from collections import deque input = stdin.readline R, C = map(int,input().split()) mat = [input().rstrip() for _ in range(R)] # 방문 확인 visited = [[[0,0] for _ in range(C)] for _ in range(R)] visited[0][0][0] = 1 # 큐 q = deque([(0,0,1,.. 2021. 5. 12.