Skip to content

Commit 145b556

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 006d8a9 + ff8f33e commit 145b556

File tree

44 files changed

+1038
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1038
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codingtest_algorithm_study.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from collections import deque
2+
import sys
3+
input = sys.stdin.readline
4+
5+
dr = [1, -1, 0, 0] # down, up, right, left
6+
dc = [0, 0, 1, -1]
7+
8+
N, K = map(int, input().split())
9+
board = [] # 바이러스 정보 받아올 배열
10+
for _ in range(N):
11+
board.append(list(map(int, input().split())))
12+
13+
S, X, Y = map(int, input().split()) # 시간, 행, 열
14+
15+
q = []
16+
for i in range(N):
17+
for j in range(N):
18+
if board[i][j] != 0: # 바이러스가 있는 위치
19+
q.append((board[i][j], i, j, 0)) # 바이러스 정보, 행, 열, 흘러간 시간
20+
q.sort() # (주의) 리스트로 받아 정렬 후 queue로 변경!
21+
q = deque(q)
22+
23+
while q: # BFS
24+
viru, row, col, time = q.popleft()
25+
if time == S: # 시간이 S만큼 지났다면 종료
26+
break
27+
for d in range(4): # 상하좌우 이동
28+
r = row + dr[d]
29+
c = col + dc[d]
30+
if -1 < r < N and -1 < c < N and not board[r][c]: # 범위를 벗어나지 않고 위치 값이 0일 때
31+
board[r][c] = viru # 바이러스 배치
32+
q.append((viru, r, c, time+1)) # 다음 번 위치를 큐에 저장
33+
34+
print(board[X-1][Y-1])
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import sys
2+
from collections import deque
3+
4+
#1. 입력값 받기
5+
#2. 모든 배열을 돌며 인구이동 조건을 만족하는 나라가 있는지 확인. (1. 인접한 나라 2. 두 국가의 인구 차의 절댓값이 l이상 r이하)
6+
#3. 인구 이동조건을 만족하는 나라가 있으면 bfs로 그래프를 탐색하면서 나라의 개수와 인구의 총합을 구해서 새로운 인구를 구해준다.
7+
#4. visited 배열은 인구 이동날마다 초기화 해야 한다.
8+
9+
# 실제로 인구를 이동시키는 함수
10+
def movePopulation(i, j):
11+
global n, l, r
12+
global visited, arr
13+
14+
dx = [-1, 1, 0, 0]
15+
dy = [0, 0, -1, 1]
16+
17+
queue = deque([(i, j)])
18+
visited[i][j] = 1
19+
queue2 = deque([(i, j)])
20+
populationSum = arr[i][j]
21+
countrySum = 1
22+
23+
while queue:
24+
x, y = queue.popleft()
25+
26+
for d in range(4):
27+
row = x + dx[d]
28+
col = y + dy[d]
29+
30+
if 0 <= row < n and 0 <= col < n and visited[row][col] == 0 and l <= abs(arr[x][y] - arr[row][col]) <= r:
31+
visited[row][col] = 1
32+
countrySum += 1
33+
populationSum += arr[row][col]
34+
queue.append((row, col))
35+
queue2.append((row, col))
36+
37+
newPopulation = populationSum // countrySum
38+
39+
while queue2:
40+
x, y = queue2.popleft()
41+
arr[x][y] = newPopulation
42+
43+
# 인구 이동 조건을 만족하는 나라가 있는지 확인하는 함수
44+
def checkCountries():
45+
global ans
46+
47+
dx = [-1, 1, 0, 0]
48+
dy = [0, 0, -1, 1]
49+
50+
for i in range(n):
51+
for j in range(n):
52+
for k in range(4):
53+
row = i + dx[k]
54+
col = j + dy[k]
55+
if 0 <= row < n and 0 <= col < n and l <= abs(arr[i][j] - arr[row][col]) <= r:
56+
ans += 1
57+
return True
58+
59+
return False
60+
61+
62+
inp = sys.stdin.readline
63+
64+
n, l, r = map(int, inp().split())
65+
66+
arr = []
67+
visited = [[0] * n for _ in range(n)]
68+
69+
ans = 0
70+
71+
for i in range(n):
72+
arr.append(list(map(int, inp().split())))
73+
74+
while checkCountries():
75+
for i in range(n):
76+
for j in range(n):
77+
if visited[i][j] == 0:
78+
movePopulation(i, j)
79+
visited = [[0] * n for _ in range(n)]
80+
81+
print(ans)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
3+
inp = sys.stdin.readline
4+
5+
arr = inp().split()
6+
7+
n = arr[0]
8+
b = int(arr[1])
9+
10+
ans = 0
11+
i = 1
12+
length = len(n)
13+
14+
for char in n:
15+
if char >= 'A' and char<='Z':
16+
ans = ans + pow(b,length - i) * (ord(char) - ord('A') + 10)
17+
else:
18+
ans = ans + pow(b,length - i) * int(char)
19+
i+=1
20+
21+
print(ans)

0 commit comments

Comments
 (0)