| ์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
- ํด๋ฆฐ์ฝ๋
- knn_classify
- ํ์ด์ฌ
- Key ์ข ๋ฅ
- ํ
- DROPTABLE
- ๋ถ๊ฝ๋ฐ์ดํฐ์
- RENAMETABLE
- ๋ฌธ์์ด
- ์ฌ์ดํท๋ฐ
- ALTERTABLE
- latent factor
- latent factor model
- ์ธ๋๋ณ๊ฐ๋น์ง์ปฌ๋ ํฐ
- ์ ์ฌ์์๋ชจ๋ธ
- ์ฃผ์ฑ๋ถ ์ฐพ๊ธฐ
- ํค ์ข ๋ฅ
- ์๊ณ ๋ฆฌ์ฆ
- SQL
- TDD
- ๋ฌด๊ฒฐ์ฑ์ ์ง๋ฉ์ปค๋์ฆ
- ์ปจํ ์ด๋๊ฐ์ฒด
- Python
- ๋ฌด๊ฒฐ์ฑ์ ์ง
- ๋ฌด๊ฒฐ์ฑ
- SQLDDL
- sklearn
- ๋ฐฑ์ค
- CREATETABLE
- Hyperlink Graphs
- Today
- Total
DonHurry
[Python] ๋ฐฑ์ค 14499๋ฒ - ์ฃผ์ฌ์ ๊ตด๋ฆฌ๊ธฐ ๋ณธ๋ฌธ
๐ ๋ฌธ์
14499๋ฒ: ์ฃผ์ฌ์ ๊ตด๋ฆฌ๊ธฐ
์ฒซ์งธ ์ค์ ์ง๋์ ์ธ๋ก ํฌ๊ธฐ N, ๊ฐ๋ก ํฌ๊ธฐ M (1 ≤ N, M ≤ 20), ์ฃผ์ฌ์๋ฅผ ๋์ ๊ณณ์ ์ขํ x, y(0 ≤ x ≤ N-1, 0 ≤ y ≤ M-1), ๊ทธ๋ฆฌ๊ณ ๋ช ๋ น์ ๊ฐ์ K (1 ≤ K ≤ 1,000)๊ฐ ์ฃผ์ด์ง๋ค. ๋์งธ ์ค๋ถํฐ N๊ฐ์ ์ค์ ์ง
www.acmicpc.net
๐ ํ์ด
๋ฐฑ์ค ์ผ์ฑ SW ์ญ๋ ํ ์คํธ ๊ธฐ์ถ ๋ฌธ์ ์ง์ ์๋ ๋ฌธ์ ๋ก, ์ ํ์ ์ธ ๊ตฌํ ๋ฌธ์ ์ ๋๋ค. ๊ฐ์ฅ ๋จผ์ ์ฐพ์์ผํ ๊ฒ์ ์ฃผ์ฌ์๊ฐ ๋์๋จ๋ถ ๊ฐ๊ฐ์ผ๋ก ์ด๋ํ์ ๋, ๊ธฐ์กด ์์น์ ์ด๋ป๊ฒ ๋ฌ๋ผ์ง๋ ๊ฐ์ ๋๋ค. ์๋ ํ๋ ๋ฌธ์ ์์ ์ฃผ์ด์ง ์ฃผ์ฌ์ ์ ๊ฐ๋๋ฅผ ๊ฐ ๋ฐฉํฅ์ผ๋ก ์ด๋ํ์ ๋์ ๋ณํ๋ฅผ ๋ํ๋ธ ํ์ ๋๋ค.
| ๋ฐฉํฅ / ์ธ๋ฑ์ค | 1 | 2 | 3 | 4 | 5 | 6 |
| 1 (๋์ชฝ) | 3 | 2 | 6 | 1 | 5 | 4 |
| 2 (์์ชฝ) | 4 | 2 | 1 | 6 | 5 | 3 |
| 3 (๋ถ์ชฝ) | 2 | 6 | 3 | 4 | 1 | 5 |
| 4 (๋จ์ชฝ) | 5 | 1 | 3 | 4 | 6 | 2 |
๋น ๋ฅธ ์๊ฐ ๋ด์ ํด๊ฒฐํ๊ณ ์ ํ๋ค๋ฉด, ๊ฒฝ์ฐ์ ์๊ฐ ๋ง์ง ์๊ธฐ ๋๋ฌธ์ ์๋ ์ฝ๋์ ๊ฐ์ด ๋ฐฉํฅ์ ๋ฐ๋ผ ์ฃผ์ฌ์ ์์น๋ฅผ ๋ฐ๊พธ์ด์ฃผ๋ฉด ๋ฉ๋๋ค. ํ์ด์ฌ์ ๋ณ์์ ๋ค์ค ํ ๋น์ ํธ๋ฆฌํ๊ฒ ํ ์ ์์ต๋๋ค. ์ฃผ์ฌ์๊ฐ ์ด๋ํ๋ ๊ท์น๋ง ์ค์ ํ๋ค๋ฉด, ๋๋จธ์ง ๊ตฌํ์ด ์ด๋ ค์ด ๋ฌธ์ ๋ ์๋์์ต๋๋ค.
๐ป ์ฝ๋
import sys
input=sys.stdin.readline
n, m, x, y, k = map(int, input().split())
grid = []
for _ in range(n):
grid.append(list(map(int, input().split())))
orders = list(map(int, input().split()))
dice = [0] * 7
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
for i in range(k):
order = orders[i]
# ์๋ก์ด ์ขํ ์ค์
new_x = x + dx[order-1]
new_y = y + dy[order-1]
# ๋ฐ๊นฅ์ผ๋ก ์ด๋ํ๋ ๊ฒฝ์ฐ ๋ช
๋ น ๋ฌด์
if not (0 <= new_x < n) or not (0 <= new_y < m):
continue
# ์ฃผ์ฌ์ ์ด๋
if order == 1:
dice[1], dice[3], dice[4], dice[6] = dice[3], dice[6], dice[1], dice[4]
elif order == 2:
dice[1], dice[3], dice[4], dice[6] = dice[4], dice[1], dice[6], dice[3]
elif order == 3:
dice[1], dice[2], dice[5], dice[6] = dice[2], dice[6], dice[1], dice[5]
elif order == 4:
dice[1], dice[2], dice[5], dice[6] = dice[5], dice[1], dice[6], dice[2]
# ์ฃผ์ฌ์์ ๋ฐ๋ฅ๋ฉด๊ณผ ์นธ์ ์ฐ์ฌ ์๋ ์ ๋ณ๊ฒฝ
if grid[new_x][new_y] == 0:
grid[new_x][new_y] = dice[1]
else:
dice[1] = grid[new_x][new_y]
grid[new_x][new_y] = 0
# ์ขํ ์ ์ฅ
x = new_x
y = new_y
print(dice[6])'Problem Solving' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [Python] ๋ฐฑ์ค 2133๋ฒ - ํ์ผ ์ฑ์ฐ๊ธฐ (0) | 2024.01.22 |
|---|---|
| [Python] ๋ฐฑ์ค 14891๋ฒ - ํฑ๋๋ฐํด (0) | 2024.01.21 |
| [Python] ๋ฐฑ์ค 9084๋ฒ - ๋์ (1) | 2024.01.19 |
| [Python] ๋ฐฑ์ค 3190๋ฒ - ๋ฑ (0) | 2024.01.17 |
| [Python] ๋ฐฑ์ค 1715๋ฒ - ์นด๋ ์ ๋ ฌํ๊ธฐ (0) | 2022.12.26 |