Skip to content

sds특강 1일차 #96

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

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmkim/BaekJoon/백준_1039.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
n, k = map(int, input().split())

32 changes: 32 additions & 0 deletions cmkim/BaekJoon/백준_1062.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def main():
n = int(input())
k = int(input())
result = 0
if k < 5:
return result
ord_cc = list(map(int, input().split())) # 후보 추천 순서

frame = []
score = []

for i in range(k):
if ord_cc[i] in frame:
for j in range(len(frame)):
if ord_cc[i] == frame[j]:
score[j] += 1
else:
if len(frame) >= n:
for j in range(n):
if score[j] == min(score):
del frame[j]
del score[j]
break
frame.append(ord_cc[i])
score.append(1)
# print(score)
# print(frame)
frame.sort()
print(' '.join(map(str, frame)))

main()

85 changes: 85 additions & 0 deletions cmkim/BaekJoon/백준_1103.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from _collections import deque
import sys
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())

dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

arr = [list(map(str, input())) for _ in range(n)]
dp = [[0] * m for _ in range(n)]
visited = [[0] * m for _ in range(n)] #dp 배열추가
# q = deque()
# q.append((0, 0, 1))# x, y 좌표와 움직인 횟수
result = 0 # 가장 큰 값을 저장해줄 변수

def bfs(x, y, count):
global result
result = max(result, count)

for i in range(4):
nx = x + dx[i] * int(arr[x][y])
ny = y + dy[i] * int(arr[x][y])

if 0 <= nx < n and 0 <= ny < m and arr[nx][ny] != 'H' and dp[nx][ny] < count + 1: #적은 이동횟수는 무시하는 조건 추가
if visited[nx][ny]:
print(-1)
exit()
else:
dp[nx][ny] = count + 1
visited[nx][ny] = 1
bfs(nx, ny, count+1)
visited[nx][ny] = 0

bfs(0, 0, 0)
print(result + 1)

# while q:
# x, y, count = q.popleft()
#
# if count > n*m: #무한 반복될때 종료조건
# print(-1)
# quit()
# for i in range(4):
# nx = x + dx[i] * int(arr[x][y])
# ny = y + dy[i] * int(arr[x][y])
#
# if 0 <= nx < n and 0 <= ny < m and arr[nx][ny] != 'H' and visited[nx][ny] < count: #적은 이동횟수는 무시하는 조건 추가
# q.append((nx, ny, count+1))
# visited[nx][ny] = count
#
#
# for i in range(n):
# for j in range(m):
# result = max(result, visited[i][j])
#
# if result < n*m:
# print(result + 1)
# else:
# print(-1)


# bfs 함수 따로 뽑아서 하는거랑 메인에서 q 구현해서 하는거랑 대체 무슨 차이?
# 밑에 1크게 시작하는거랑 무슨차이?
'''
def bfs(x, y, count):
global result
result = max(result, count)

for i in range(4):
nx = x + dx[i] * int(arr[x][y])
ny = y + dy[i] * int(arr[x][y])

if 0 <= nx < n and 0 <= ny < m and arr[nx][ny] != 'H' and dp[nx][ny] < count: #적은 이동횟수는 무시하는 조건 추가
if visited[nx][ny]:
print(-1)
exit()
else:
dp[nx][ny] = count +1
visited[nx][ny] = 1
bfs(nx, ny, count+1)
visited[nx][ny] = 0

bfs(0, 0, 1)
print(result)
'''
File renamed without changes.
3 changes: 2 additions & 1 deletion cmkim/BaekJoon/백준_1920.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
else:
print(0, end="\n")
else:
print(0, end="\n")
print(0, end="\n")

60 changes: 60 additions & 0 deletions cmkim/BaekJoon/백준_3055.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from collections import deque

dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

def water():
qlen = len(wq)
while qlen:
x, y = wq.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < r and 0 <= ny < c:
if a[nx][ny] == '.':
a[nx][ny] = '*'
wq.append([nx, ny])
qlen -= 1

def bfs(x, y):
q.append([x, y])
visited[x][y] = 1
while q:
qlen = len(q)
while qlen:
x, y = q.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < r and 0 <= ny < c:
if a[nx][ny] == '.' and visited[nx][ny] == 0:
visited[nx][ny] = visited[x][y] + 1
q.append([nx, ny])
elif a[nx][ny] == 'D':
print(visited[x][y])
return
qlen -= 1
water()

print("KAKTUS")
return


r, c = map(int, input().split())
a = [list(map(str, input())) for _ in range(r)]
visited = [[0]*c for _ in range(r)]
q, wq = deque(), deque()

for i in range(r):
for j in range(c):
if a[i][j] == 'S':
x1, y1 = i, j
a[i][j] = '.'
elif a[i][j] == '*':
wq.append((i, j))

water()
bfs(x1, y1)