곰퓨타의 SW 이야기

[12-06 구현 문제] 기둥과 보 설치 본문

TIL/이것이 코딩테스트다_파이썬 문제 (백준문제 外)

[12-06 구현 문제] 기둥과 보 설치

곰퓨타 2021. 5. 6. 22:52

최근 보고 있는 책인  '이것이 코딩테스트다 with 파이썬 편_나동빈_한빛미디어' 에 있는 문제이다.

www.hanbit.co.kr/store/books/look.php?p_code=B8945183661

 

이것이 취업을 위한 코딩 테스트다 with 파이썬

IT 취준생이라면 누구나 가고 싶어 하는 카카오, 라인, 삼성전자의 2016년부터 2020년까지의 코딩 테스트와 알고리즘 대회의 기출문제를 엄선하여 수록하였다.

www.hanbit.co.kr

 

 

문제는 프로그래머스에 있다.

programmers.co.kr/learn/courses/30/lessons/60061

 

코딩테스트 연습 - 기둥과 보 설치

5 [[1,0,0,1],[1,1,1,1],[2,1,0,1],[2,2,1,1],[5,0,0,1],[5,1,0,1],[4,2,1,1],[3,2,1,1]] [[1,0,0],[1,1,1],[2,1,0],[2,2,1],[3,2,1],[4,2,1],[5,0,0],[5,1,0]] 5 [[0,0,0,1],[2,0,0,1],[4,0,0,1],[0,1,1,1],[1,1,1,1],[2,1,1,1],[3,1,1,1],[2,0,0,0],[1,1,1,0],[2,2,0,1]] [[

programmers.co.kr

 

 

 

 

 

def possible(ans):
    for i in ans:
        x,y,type = i
        if type == 0:
            # 바닥 위
            if y==0 :
                continue
            # 보의 한 쪽 끝 위
            if [x-1,y,1] in ans or [x,y,1] in ans :
                continue
            # 다른 기둥 위
            if [x,y-1,0] in ans :
                continue
        else :
            # 한쪽 끝이 기둥 위
            if [x,y-1,0] in ans or [x+1,y-1,0] in ans :
                continue
            # 양쪽 끝이 다른 보와 연결
            if [x-1,y,1] in ans and [x+1,y,1] in ans :
                continue
        return False

    return True
def solution(n, build_frame):
    answer = []
    for i in build_frame:
        if i[3] == 0 :
            answer.remove([i[0],i[1],i[2]])
            # 삭제
            if not possible(answer) :
                answer.append([i[0],i[1],i[2]])

        else :
            answer.append([i[0],i[1],i[2]])
            # 설치
            if not possible(answer):
                answer.remove([i[0],i[1],i[2]])

    answer.sort()
    return answer

 

Comments