Post

아기 상어

백준 사이트의 16236번 문제

코딩 계획

  1. 입력값을 받아 정수로 변환해서 변수에 저장
  2. 아기 상어의 위치 탐색해서 기록
  3. BFS로 아기 상어 행동 구현
    1. 이동 가능한 위치 탐색
    2. 가장 위, 가장 왼쪽이 우선이 되게 정렬
    3. 물고기를 먹을 수 있는지 확인
    4. 아기 상어 크기, 위치 조정
  4. 물고기 제거, 이동 시간 누적합
  5. 결과 출력

코드 구성

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Ocean:
    def __init__(self, n):
        self.size = n
        
    def input(self):
        self.grid = []
        for _ in range(n):
            self.grid.append(list(map(int, input().split())))

        
class BabyShark:
    def __init__(self, ocean):
        self.size = 2
        self.eat_count = 0
        self.location = self.locate(ocean)
        
    def locate(self, ocean):
        pass
                
    def eatable(self, x, y, ocean):
        pass
        
    def eat(self, x, y):
        pass
        

def movable(x, y, size, ocean, visited):
    pass
    
def bfs(baby_shark, ocean):
    pass    
        
        
n = int(input())

ocean = Ocean(n)
ocean.input()

baby_shark = BabyShark(ocean)

total_time = 0
while True:
    travel_time = bfs(baby_shark, ocean)
    if travel_time > 0:
        total_time += travel_time
    else:
        break
    
print(total_time)

최종 코드

https://github.com/yehoon17/beakjoon/blob/main/python/16236.py

This post is licensed under CC BY 4.0 by the author.