Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

53-tgyuuAn #184

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions tgyuuAn/DFS/2048 (Easy).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import sys, copy
N = int(input())
pan = []
ans = 0

for _ in range(N):
pan.append([int(x) for x in sys.stdin.readline().rstrip().split()])

def left(board):
for i in range(N):
cursor = 0
for j in range(1, N):
if board[i][j] != 0: # 0์ด ์•„๋‹Œ ๊ฐ’์ด
tmp = board[i][j]
board[i][j] = 0 # ์ผ๋‹จ ๋น„์›Œ์งˆ๊บผ๋‹ˆ๊นŒ 0์œผ๋กœ ๋ฐ”๊ฟˆ

if board[i][cursor] == 0: # ๋น„์–ด์žˆ์œผ๋ฉด
board[i][cursor] = tmp # ์˜ฎ๊ธด๋‹ค

elif board[i][cursor] == tmp: # ๊ฐ™์œผ๋ฉด
board[i][cursor] *= 2 # ํ•ฉ์นœ๋‹ค
cursor += 1
else: # ๋น„์–ด์žˆ์ง€๋„ ์•Š๊ณ  ๋‹ค๋ฅธ ๊ฐ’์ผ๋•Œ
cursor += 1 # pass
board[i][cursor] = tmp # ๋ฐ”๋กœ ์˜†์— ๋ถ™์ž„

return board

def right(board):
for i in range(N):
cursor = N - 1
for j in range(N - 1, -1, -1):

if board[i][j] != 0:
tmp = board[i][j]
board[i][j] = 0

if board[i][cursor] == 0:
board[i][cursor] = tmp

elif board[i][cursor] == tmp:
board[i][cursor] *= 2
cursor -= 1
else:
cursor -= 1
board[i][cursor] = tmp
return board

def up(board):
for j in range(N):
cursor = 0
for i in range(N):
if board[i][j] != 0:
tmp = board[i][j]
board[i][j] = 0

if board[cursor][j] == 0:
board[cursor][j] = tmp

elif board[cursor][j] == tmp:
board[cursor][j] *= 2
cursor += 1

else:
cursor += 1
board[cursor][j] = tmp
return board

def down(board):
for j in range(N):
cursor = N - 1
for i in range(N - 1, -1, -1):
if board[i][j] != 0:
tmp = board[i][j]
board[i][j] = 0

if board[cursor][j] == 0:
board[cursor][j] = tmp

elif board[cursor][j] == tmp:
board[cursor][j] *= 2
cursor -= 1

else:
cursor -= 1
board[cursor][j] = tmp
return board

def dfs(n, arr):
global ans
if n == 5:
for i in range(N):
for j in range(N):
if arr[i][j] > ans:
ans = arr[i][j]
return

for i in range(4):
copy_arr = copy.deepcopy(arr)
if i == 0:
dfs(n + 1, left(copy_arr))
elif i == 1:
dfs(n + 1, right(copy_arr))
elif i == 2:
dfs(n + 1, up(copy_arr))
else:
dfs(n + 1, down(copy_arr))
Comment on lines +98 to +107
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์™ผ์ชฝ์œผ๋กœ ์›€์ง์ธ ๊ฒฝ์šฐ๋ฅผ ๋งŒ๋“  ํ›„์—
์˜ค๋ฅธ์ชฝ์œผ๋กœ ์›€์ง์ผ ๋•Œ๋Š” ์™ผ์ชฝ์œผ๋กœ ์›€์ง์ธ ๊ฒŒ์ž„ํŒ์„ ์ด์–ด์„œ ์ด์šฉํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ
์™ผ์ชฝ์œผ๋กœ ์›€์ง์ด๊ธฐ ์ „์˜ ๊ฒŒ์ž„ํŒ์„ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์›€์ง์—ฌ์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์—
๊นŠ์€ ๋ณต์‚ฌ๋ฅผ ํ†ตํ•ด์„œ ํ•˜๊ฒŒ ๋˜์—ˆ๊ตฐ์š”!!!

์ดํŒ€์€ ๋ฌธ์ œ ์ˆ˜์ค€์ด ๋„ˆ๋ฌด ๋†’์€๋ฐ ๋‚ด์ผ๋ถ€ํ„ฐ ์ž˜๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค!!!!!!๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฌธ์ œ ์ˆ˜์ค€ ๋†’์ง€ ์•Š์Šต๋‹ˆ๋‹ค... ๋‹ค ํ•˜๋ฉด ํ’€๋ฆฌ๋Š” ๊ฒƒ๋“ค ....!!!!!!!!!!!! ์•„์ž๋ตค!!!!!!!!!!!


dfs(0, pan)
print(ans)
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@
| 50์ฐจ์‹œ | 2024.04.01 | BFS | <a href="https://www.acmicpc.net/problem/9328">์—ด์‡ </a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/175
| 51์ฐจ์‹œ | 2023.04.07 | BFS | <a href="https://www.acmicpc.net/problem/5213">๊ณผ์™ธ๋งจ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/179
| 52์ฐจ์‹œ | 2023.05.06 | ์œ„์ƒ์ •๋ ฌ | <a href="https://www.acmicpc.net/problem/1516">๊ฒŒ์ž„ ๊ฐœ๋ฐœ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/182
| 53์ฐจ์‹œ | 2023.05.09 | ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://www.acmicpc.net/problem/12100">2048 (Easy)</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/184
---