-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2322656
commit 7f0ae7c
Showing
10 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ pbcopy | |
a.cpp | ||
*.bin | ||
.cph/* | ||
Archive/BOJ/.cph | ||
Archive/BOJ/.cph | ||
Coding Test/.cph/ |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
|
||
N = int(input()) | ||
curves = [list(map(int, input().rstrip().split())) for _ in range(N)] | ||
table = [[0] * 101 for _ in range(101)] | ||
|
||
def move_direction(d, g): | ||
result = [] | ||
directions = [d] | ||
for _ in range(g): | ||
size = len(directions) | ||
for i in range(size-1, -1, -1): | ||
directions.append((directions[i] + 1) % 4) | ||
return directions | ||
|
||
|
||
def move_point(direction): | ||
global table, pos_x, pos_y | ||
table[pos_x][pos_y] = 1 | ||
if direction == 0: | ||
pos_y = pos_y + 1 | ||
elif direction == 1: | ||
pos_x = pos_x - 1 | ||
elif direction == 2: | ||
pos_y = pos_y - 1 | ||
elif direction == 3: | ||
pos_x = pos_x + 1 | ||
table[pos_x][pos_y] = 1 | ||
|
||
def make_dragon_curve(d, g): | ||
directions = move_direction(d, g) | ||
# print(directions) | ||
for direction in directions: | ||
move_point(direction) | ||
|
||
def check(): | ||
global table | ||
count = 0 | ||
for i in range(100): | ||
for j in range(100): | ||
if table[i][j] == 1 and table[i][j+1] == 1 and table[i+1][j] == 1 and table[i+1][j+1] == 1: | ||
count += 1 | ||
return count | ||
|
||
pos_x = pos_y = 0 | ||
for x, y, d, g in curves: | ||
pos_x, pos_y = y, x | ||
make_dragon_curve(d, g) | ||
|
||
|
||
print(check()) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
T = int(input()) | ||
|
||
def get_peek(): | ||
global mountain, N | ||
result = [] | ||
peek_num = max([max(x) for x in mountain]) | ||
for i in range(N): | ||
for j in range(N): | ||
if mountain[i][j] == peek_num: | ||
result.append((i, j)) | ||
return result | ||
|
||
def is_valid(x, y): | ||
if 0 <= x < N and 0 <= y < N: | ||
return True | ||
return False | ||
|
||
def can_move(cur_x, cur_y, next_x, next_y): | ||
global mountain | ||
if mountain[cur_x][cur_y] > mountain[next_x][next_y]: | ||
return True | ||
return False | ||
|
||
|
||
def dfs(cur_x, cur_y, length): | ||
global result, mountain | ||
dmove = [(0, 1), (0, -1), (1, 0), (-1, 0)] | ||
for dx, dy in dmove: | ||
next_x, next_y = cur_x + dx, cur_y + dy | ||
if is_valid(next_x, next_y) and can_move(cur_x, cur_y, next_x, next_y): | ||
dfs(next_x, next_y, length + 1) | ||
else: | ||
result = max(result, length) | ||
|
||
N = K = 0 | ||
mountain = [] | ||
mountain_peeks = [] | ||
result = 1 | ||
|
||
for t in range(T): | ||
N, K = list(map(int, input().rstrip().split())) | ||
mountain = [list(map(int, input().rstrip().split())) for _ in range(N)] | ||
mountain_peeks = get_peek() | ||
result = 1 | ||
for peek_x, peek_y in mountain_peeks: | ||
for x in range(N): | ||
for y in range(N): | ||
for k in range(0, K+1): | ||
mountain[x][y] -= k | ||
dfs(peek_x, peek_y, 1) | ||
mountain[x][y] += k | ||
|
||
print("#{} {}".format(t+1, result)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from collections import deque | ||
|
||
T = int(input()) | ||
|
||
N, M, R, C, L = 0, 0, 0, 0, 0 | ||
tunnel = [] | ||
visited = [] | ||
result = 0 | ||
|
||
|
||
def is_valid(x, y): | ||
global N, M | ||
if 0 <= x < N and 0 <= y < M: | ||
return True | ||
return False | ||
|
||
|
||
def can_move(cur_x, cur_y, go_x, go_y, direction): | ||
global tunnel | ||
if direction == 0: | ||
if tunnel[go_x][go_y] in [1, 2, 5, 6]: | ||
return True | ||
elif direction == 1: | ||
if tunnel[go_x][go_y] in [1, 3, 6, 7]: | ||
return True | ||
elif direction == 2: | ||
if tunnel[go_x][go_y] in [1, 2, 4, 7]: | ||
return True | ||
elif direction == 3: | ||
if tunnel[go_x][go_y] in [1, 3, 4, 5]: | ||
return True | ||
return False | ||
|
||
|
||
def count(): | ||
global visited, L | ||
count = 0 | ||
for i in range(N): | ||
for j in range(M): | ||
if 0 < visited[i][j] <= L: | ||
count += 1 | ||
return count | ||
|
||
|
||
def bfs(): | ||
global N, M, R, C, L | ||
queue = deque([[R, C]]) | ||
visited[R][C] = 1 | ||
cnt = 0 | ||
while queue: | ||
x, y = queue.popleft() | ||
dirs = [ | ||
[], | ||
[[-1, 0, 0], [0, 1, 1], [1, 0, 2], [0, -1, 3]], # 위 -> 아래 <- | ||
[[-1, 0, 0], [1, 0, 2]], # 위 아래 | ||
[[0, 1, 1], [0, -1, 3]], # -> <- | ||
[[-1, 0, 0], [0, 1, 1]], # 위 -> | ||
[[1, 0, 2], [0, 1, 1]], # 아래 -> | ||
[[1, 0, 2], [0, -1, 3]], # 아래 <- | ||
[[0, -1, 3], [-1, 0, 0]] # <- 위 | ||
] | ||
for direction in (dirs[tunnel[x][y]]): | ||
next_x, next_y = x + direction[0], y + direction[1] | ||
if is_valid(next_x, next_y) and can_move(x, y, next_x, next_y, direction[2]) and visited[next_x][next_y] == 0: | ||
queue.append([next_x, next_y]) | ||
visited[next_x][next_y] = visited[x][y] + 1 | ||
|
||
|
||
for i in range(1, T+1): | ||
N, M, R, C, L = list(map(int, input().rstrip().split())) | ||
tunnel = [list(map(int, input().rstrip().split())) for _ in range(N)] | ||
visited = [[0] * M for _ in range(N)] | ||
bfs() | ||
print("#{} {}".format(i, count())) |
File renamed without changes.