Skip to content

Commit fbe053a

Browse files
authored
sds특강 1일차 (#96)
1 parent 5526c25 commit fbe053a

File tree

6 files changed

+181
-1
lines changed

6 files changed

+181
-1
lines changed

‎cmkim/BaekJoon/백준_1039.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
n, k = map(int, input().split())
2+

‎cmkim/BaekJoon/백준_1062.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def main():
2+
n = int(input())
3+
k = int(input())
4+
result = 0
5+
if k < 5:
6+
return result
7+
ord_cc = list(map(int, input().split())) # 후보 추천 순서
8+
9+
frame = []
10+
score = []
11+
12+
for i in range(k):
13+
if ord_cc[i] in frame:
14+
for j in range(len(frame)):
15+
if ord_cc[i] == frame[j]:
16+
score[j] += 1
17+
else:
18+
if len(frame) >= n:
19+
for j in range(n):
20+
if score[j] == min(score):
21+
del frame[j]
22+
del score[j]
23+
break
24+
frame.append(ord_cc[i])
25+
score.append(1)
26+
# print(score)
27+
# print(frame)
28+
frame.sort()
29+
print(' '.join(map(str, frame)))
30+
31+
main()
32+

‎cmkim/BaekJoon/백준_1103.py

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from _collections import deque
2+
import sys
3+
sys.setrecursionlimit(10**6)
4+
n, m = map(int, input().split())
5+
6+
dx = [-1, 1, 0, 0]
7+
dy = [0, 0, -1, 1]
8+
9+
arr = [list(map(str, input())) for _ in range(n)]
10+
dp = [[0] * m for _ in range(n)]
11+
visited = [[0] * m for _ in range(n)] #dp 배열추가
12+
# q = deque()
13+
# q.append((0, 0, 1))# x, y 좌표와 움직인 횟수
14+
result = 0 # 가장 큰 값을 저장해줄 변수
15+
16+
def bfs(x, y, count):
17+
global result
18+
result = max(result, count)
19+
20+
for i in range(4):
21+
nx = x + dx[i] * int(arr[x][y])
22+
ny = y + dy[i] * int(arr[x][y])
23+
24+
if 0 <= nx < n and 0 <= ny < m and arr[nx][ny] != 'H' and dp[nx][ny] < count + 1: #적은 이동횟수는 무시하는 조건 추가
25+
if visited[nx][ny]:
26+
print(-1)
27+
exit()
28+
else:
29+
dp[nx][ny] = count + 1
30+
visited[nx][ny] = 1
31+
bfs(nx, ny, count+1)
32+
visited[nx][ny] = 0
33+
34+
bfs(0, 0, 0)
35+
print(result + 1)
36+
37+
# while q:
38+
# x, y, count = q.popleft()
39+
#
40+
# if count > n*m: #무한 반복될때 종료조건
41+
# print(-1)
42+
# quit()
43+
# for i in range(4):
44+
# nx = x + dx[i] * int(arr[x][y])
45+
# ny = y + dy[i] * int(arr[x][y])
46+
#
47+
# if 0 <= nx < n and 0 <= ny < m and arr[nx][ny] != 'H' and visited[nx][ny] < count: #적은 이동횟수는 무시하는 조건 추가
48+
# q.append((nx, ny, count+1))
49+
# visited[nx][ny] = count
50+
#
51+
#
52+
# for i in range(n):
53+
# for j in range(m):
54+
# result = max(result, visited[i][j])
55+
#
56+
# if result < n*m:
57+
# print(result + 1)
58+
# else:
59+
# print(-1)
60+
61+
62+
# bfs 함수 따로 뽑아서 하는거랑 메인에서 q 구현해서 하는거랑 대체 무슨 차이?
63+
# 밑에 1크게 시작하는거랑 무슨차이?
64+
'''
65+
def bfs(x, y, count):
66+
global result
67+
result = max(result, count)
68+
69+
for i in range(4):
70+
nx = x + dx[i] * int(arr[x][y])
71+
ny = y + dy[i] * int(arr[x][y])
72+
73+
if 0 <= nx < n and 0 <= ny < m and arr[nx][ny] != 'H' and dp[nx][ny] < count: #적은 이동횟수는 무시하는 조건 추가
74+
if visited[nx][ny]:
75+
print(-1)
76+
exit()
77+
else:
78+
dp[nx][ny] = count +1
79+
visited[nx][ny] = 1
80+
bfs(nx, ny, count+1)
81+
visited[nx][ny] = 0
82+
83+
bfs(0, 0, 1)
84+
print(result)
85+
'''
File renamed without changes.

‎cmkim/BaekJoon/백준_1920.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424
else:
2525
print(0, end="\n")
2626
else:
27-
print(0, end="\n")
27+
print(0, end="\n")
28+

‎cmkim/BaekJoon/백준_3055.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from collections import deque
2+
3+
dx = [-1, 1, 0, 0]
4+
dy = [0, 0, -1, 1]
5+
6+
def water():
7+
qlen = len(wq)
8+
while qlen:
9+
x, y = wq.popleft()
10+
for i in range(4):
11+
nx = x + dx[i]
12+
ny = y + dy[i]
13+
if 0 <= nx < r and 0 <= ny < c:
14+
if a[nx][ny] == '.':
15+
a[nx][ny] = '*'
16+
wq.append([nx, ny])
17+
qlen -= 1
18+
19+
def bfs(x, y):
20+
q.append([x, y])
21+
visited[x][y] = 1
22+
while q:
23+
qlen = len(q)
24+
while qlen:
25+
x, y = q.popleft()
26+
for i in range(4):
27+
nx = x + dx[i]
28+
ny = y + dy[i]
29+
if 0 <= nx < r and 0 <= ny < c:
30+
if a[nx][ny] == '.' and visited[nx][ny] == 0:
31+
visited[nx][ny] = visited[x][y] + 1
32+
q.append([nx, ny])
33+
elif a[nx][ny] == 'D':
34+
print(visited[x][y])
35+
return
36+
qlen -= 1
37+
water()
38+
39+
print("KAKTUS")
40+
return
41+
42+
43+
r, c = map(int, input().split())
44+
a = [list(map(str, input())) for _ in range(r)]
45+
visited = [[0]*c for _ in range(r)]
46+
q, wq = deque(), deque()
47+
48+
for i in range(r):
49+
for j in range(c):
50+
if a[i][j] == 'S':
51+
x1, y1 = i, j
52+
a[i][j] = '.'
53+
elif a[i][j] == '*':
54+
wq.append((i, j))
55+
56+
water()
57+
bfs(x1, y1)
58+
59+
60+

0 commit comments

Comments
 (0)