๋ฐ์ํ
๐ค๋ฌธ์ ํด๊ฒฐ
-
G4 | ๊ตฌํ, ์๋ฎฌ๋ ์ด์
์ขํ๋ฅผ ๊ตฌํด์ ํ์ ์ ์์ผ๊ฐ๋ฉฐ ๊ตฌํ๋ ค๊ณ ํ์ง๋ง ๋์ ํ ์๋๊ฑฐ ๊ฐ์๋ค.
( ๋ฐฉํฅ์ด ์ฃผ์ด์ก๋๋ฐ ์ฒ์ 1๋ฒ๋ง์ฐ๊ณ ๋ฒ๋ฆฌ๋? ๋ผ๊ณ ์๊ฐํ์ )
๋ฐฉํฅ์ผ๋ก ๋ณด๋ ๊ท์น์ฑ์ด ์์๋ค.
- 0์ธ๋: 0
- 1์ธ๋: 0 | 1
- 2์ธ๋: 0 1 | 2 1
- 3์ธ๋: 0 1 2 1 | 2 3 2 1
์ด์ ๊ตฌํ๋ ์์๋
- ๋๋๊ณค ์ปค๋ธํ๋(ํ์ค)์ ๋ฐฉํฅ๋ค ๊ตฌํ๊ธฐ
- ๋๋๊ณค ์ปค๋ธํ๋์ ์์์ ์ ๊ธฐ์ค์ผ๋ก ๋ฐฉํฅ์ ๋ฐ๋ผ ์ญ์ญ ์ขํ์จ๋ด๋ ค๊ฐ๊ธฐ
- ๋ชจ๋ ๋๋๊ณค ์ปค๋ธ๋ฅผ ๋งต์ ํ์ํ๋ค๋ฉด ๋ค๋ชจ ๊ตฌํ๊ธฐ
๐ป์์ค ์ฝ๋
import sys
input = sys.stdin.readline
def make_curve(x, y, d, g):
# ์ขํ๋ก ํธ๋๊ฒ์ด ์๋๋ผ ๊ท์น์ ์ฐพ์ ์งํ๋ฐฉํฅ์ผ๋ก ํผ๋ค!
# ์งํ๋ฐฉํฅ์ ์ง๊ธ๊น์ง ์งํํด์จ ๊ฒ๋ค์ ์ญ์์ผ๋ก ๊บผ๋ด์ ๋ฐ์๊ณ 90๋ ํ์ ์ํจ๋ค.
directions = [d]
for i in range(g):
for j in range(len(directions) - 1, -1, -1):
# 0 -> 1, 1 -> 2, 2 -> 3, 3 -> 0
directions.append((directions[j] + 1) % 4)
# print(directions)
return directions
def set_coordinates(x, y, directions):
# ์งํ๋ฐฉํฅ์ ๊ตฌํ์ผ๋ฉด ์ขํ๋ฅผ ๊ตฌํ๋ค.
# ์ ์ฒด ํฌ๊ธฐ๋ 101 x 101
# ์ฐ, ์, ์ข, ํ
dx, dy = [0, -1, 0, 1], [1, 0, -1, 0]
maps[x][y] = 1 # ์ฒซ ์ขํ๋ฅผ ํ์ ์ํด์ฃผ๋ฉด ๊ณ ์ฅ๋จ
for k in directions:
x += dx[k]
y += dy[k]
maps[x][y] = 1
def get_square():
cnt = 0
for i in range(M - 1):
for j in range(M - 1):
# i, j๋ฅผ ๊ธฐ์ค์ผ๋ก ์ฐ, ํ, ์ฐํ ๊ฐ 1์ด๋ฉด ์ฌ๊ฐํ์ด๋ค.
if maps[i][j] and maps[i + 1][j] and maps[i][j + 1] and maps[i + 1][j + 1]:
cnt += 1
return cnt
if __name__ == '__main__':
N = int(input())
infos = [list(map(int, input().split())) for _ in range(N)]
all_curves = []
M = 101
maps = [[0] * M for _ in range(M)]
for info in infos:
# ํท๊ฐ๋ ค์ ์๋ ํ๋๋๋ก x๋ฅผ ์ธ๋ก, y๋ฅผ ๊ฐ๋ก๋ก ๋ฐ๊ฟ
y, x, d, g = info # ๊ฐ๋ก, ์ธ๋ก, ๋ฐฉํฅ, ์ธ๋
directions = make_curve(x, y, d, g)
set_coordinates(x, y, directions)
# for rw in maps:
# print(rw)
# print()
# answer
answer = get_square()
print(answer)
๐๋ฌธ์ ํ์ธ
์ถ์ฒ: BACKJOON ONLINE JUDGE
๋งํฌ: https://www.acmicpc.net/problem/15685
๋ฐ์ํ
'Algorithm Problem > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[python] SWEA - 6692. ๋ค์์ด์ ์๊ธ ์์ (0) | 2020.11.20 |
---|---|
[python] SWEA - 10570. ์ ๊ณฑ ํฐ๋ฆฐ๋๋กฌ ์ (0) | 2020.11.19 |
[python] ๋ฐฑ์ค - 14500. ํ ํธ๋ก๋ฏธ๋ ธ (์ผ์ฑ SW ์ญ๋ ํ ์คํธ ๊ธฐ์ถ ๋ฌธ์ ) (0) | 2020.11.16 |
[python] ๋ฐฑ์ค - 1261. ์๊ณ ์คํ (0) | 2020.11.15 |
[python] ๋ฐฑ์ค - 14889. ์คํํธ์ ๋งํฌ (0) | 2020.11.14 |