Skip to content

Conversation

@jinan159
Copy link
Contributor

@jinan159 jinan159 commented May 5, 2022

시간복잡도

세로 = N
가로 = M

시간 복잡도 = 빈칸의 수 * 4 방향

O(NM)

접근 과정

  • 방향 : Direction
  • 영역 상태 : AreaStatus
  • 로봇 청소기 : RobotVacuum

문제에 나오는 항목들을 객체로 만들고, 각 객체에 역할을 부여하여 구현하였습니다.

핵심이 되는 객체는 RobotVacuum 입니다.

  • RobotVacuum 의 역할
    • 구역 청소
    • 현재 방향으로 한칸 이동
    • 방향 전환

그리고 각 방향은 다음 방향을 참조하도록 하였습니다.

enum Direction {
    UP(new Point(0, -1)),
    RIGHT(new Point(1, 0)),
    DOWN(new Point(0, 1)),
    LEFT(new Point(-1, 0));

    static {
        UP.next = LEFT;
        RIGHT.next = UP;
        DOWN.next = RIGHT;
        LEFT.next = DOWN;

        UP.back = DOWN;
        RIGHT.back = LEFT;
        DOWN.back = UP;
        LEFT.back = RIGHT;
    }

    private Direction next;
    private Direction back;

    private final Point directionPoint;

    Direction(Point directionPoint) {
        this.directionPoint = directionPoint;
    }

    // ...

    public static Direction valueOf(int value) {
        switch (value) {
            case 0: return UP;
            case 1: return RIGHT;
            case 2: return DOWN;
            case 3: return LEFT;
            default: throw new IllegalArgumentException();
        }
    }
}

삽질

  • 후진의 의미를 잘못 이해함
    • 소코반에서 처럼 이전 칸으로 되돌아간다는 의미로 이해하였음
      => 문제의 의도는 현재 방향을 기준으로 뒤로 간다는 의미

@jinan159 jinan159 linked an issue May 5, 2022 that may be closed by this pull request
@jinan159 jinan159 added the BOJ label May 5, 2022
@jinan159 jinan159 self-assigned this May 5, 2022
@jinan159 jinan159 merged commit 0bbf140 into CodeSquad-Algorithm:main May 9, 2022
@jinan159 jinan159 deleted the week10_1 branch May 15, 2022 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2022.05.03(화)] BOJ(14503) : 로봇 청소기

1 participant