Skip to content

[Week 5] FORTRESS self review - profitjeanย #177

@profitjean

Description

@profitjean

FORTRESS self review

1. ํ•ด๊ฒฐ ์‹œ๋„ ๊ณผ์ •

ํ˜„์žฌ ์„ฑ์—์„œ ๊ฐ€์žฅ ๋งŽ์€ ์„ฑ๋ฒฝ์„ ๋„˜์–ด์•ผํ•˜๋Š” ๊ฒฝ๋กœ๋Š”
ํŠธ๋ฆฌ์—์„œ ๊ฐ€์žฅ ๋ฉ€๋ฆฌ ์žˆ๋Š” ๋‘ ๋…ธ๋“œ๋ฅผ ์ฐพ๋Š”๊ฒƒ๊ณผ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.
ํ˜„์žฌ ๋…ธ๋“œ๋ฅผ ๋ฃจ๋“œ๋กœ ํ•˜๋Š” ํŠธ๋ฆฌ์—์„œ ์ตœ๋Œ€ ๋†’์ด๋ฅผ ๊ตฌํ•˜๋Š” ์žฌ๊ท€ํ•จ์ˆ˜(max_height)์„ ๊ตฌํ˜„ํ•˜๊ณ 
is_child๋กœ ์—ฐ๊ฒฐ๊ด€๊ณ„๋ฅผ ํŒŒ์•…ํ•˜๊ณ ์ž ํ–ˆ์Šต๋‹ˆ๋‹ค.

2. ์ž‘์„ฑํ•œ ์ฝ”๋“œ์™€ ์„ค๋ช…

def do_enclose(root, child, walls):
    R = walls[root]
    C = walls[child]

    if R[2] > C[2]:
        return (R[2] - C[2]) ** 2 > (R[1]-C[1]) ** 2 + (R[0]-C[0]) ** 2
def is_child(root, child, walls):
    if not do_enclose(root, child, walls):
        return False
    for i in range(len(walls)):
        if i != root and i != child and do_enclose(root, i, walls) and do_enclose(i, child, walls):
            return False
    return True
class Node:
    def __init__(self, root, walls):
        self.children = []
        for i in range(len(walls)):
            if is_child(root, i, walls):
                self.children.append(i)

def max_height(walls):
    longest = 0
    # node๋ฅผ root๋กœ ํ•˜๋Š” ํŠธ๋ฆฌ์˜ ์ตœ๋Œ€ ๋†’์ด
    # ์ด ํŠธ๋ฆฌ ๋‚ด์—์„œ ๋…ธ๋“œ ๊ฐ„ ์ตœ๋Œ€ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•œ๋‹ค
    def find(root):
        node = Node(root, walls)
        heights  = []
        for child in node.childern:
            # ๋ฃจํŠธ ๋…ธ๋“œ ๋‚ด์—์„œ ์„œ๋ธŒ ํŠธ๋ฆฌ์˜ ๋†’์ด ์ €์žฅ
            heights.append(find(child))
        # ์ž์‹๋…ธ๋“œ๊ฐ€ ์—†๋‹ค๋Š” ๊ฒƒ์€ ์ž์‹ ์ด ์ œ์ผ ๋, ์žŽ ๋…ธ๋“œ
        if not heights:
            return 0

3. ๋ง‰ํžŒ ์  ๋ฐ ๊ฐœ์„  ์‚ฌํ•ญ

์ตœ๋Œ€ ๋†’์ด๋ฅผ ๊ตฌํ•˜๋Š” ๊ณผ์ •์—์„œ ๋ง‰ํ˜”์Šต๋‹ˆ๋‹ค.

Metadata

Metadata

Assignees

No one assigned

    Labels

    2๊ธฐ์Šคํ„ฐ๋”” 2๊ธฐWAWrong Answer

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions