ps | |
---|---|
링크 | programmers.co.kr/… |
출처 | 프로그래머스 |
문제 번호 | 87377 |
문제명 | 점에 별 만들기 |
레벨 | Level 2 |
분류 |
구현 |
시간복잡도 | O(n^2 + x*y) |
인풋사이즈 | n<=1000, x<=1000, y<=1000 |
사용한 언어 | Python |
해결날짜 | 2021/10/21 |
"""Solution code for "Programmers 87377. 교점에 별 만들기".
- Problem link: https://programmers.co.kr/learn/courses/30/lessons/87377
- Solution link: http://www.teferi.net/ps/problems/programmers/87377
"""
import itertools
def solution(line):
intersect_x_points, intersect_y_points = [], []
for (a, b, e), (c, d, f) in itertools.combinations(line, 2):
if (denom := a * d - b * c) == 0:
continue
x, r1 = divmod(b * f - e * d, denom)
y, r2 = divmod(e * c - a * f, denom)
if r1 == r2 == 0:
intersect_x_points.append(x)
intersect_y_points.append(y)
min_x, max_x = min(intersect_x_points), max(intersect_x_points)
min_y, max_y = min(intersect_y_points), max(intersect_y_points)
grid = [['.'] * (min_x - max_x + 1) for _ in range(min_y - max_y + 1)]
for x, y in zip(intersect_x_points, intersect_y_points):
grid[y - min_y][x - min_x] = '*'
return [''.join(row) for row in grid]