diff --git a/.DS_Store b/.DS_Store index d1f8cd31..a47ba5a1 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git "a/minjeong/DFSBFS/2024-07-22-[\353\260\261\354\244\200]-#18352-\355\212\271\354\240\225\352\261\260\353\246\254\354\235\230\353\217\204\354\213\234\354\260\276\352\270\260.py" "b/minjeong/DFSBFS/2024-07-22-[\353\260\261\354\244\200]-#18352-\355\212\271\354\240\225\352\261\260\353\246\254\354\235\230\353\217\204\354\213\234\354\260\276\352\270\260.py" new file mode 100644 index 00000000..93f03e7d --- /dev/null +++ "b/minjeong/DFSBFS/2024-07-22-[\353\260\261\354\244\200]-#18352-\355\212\271\354\240\225\352\261\260\353\246\254\354\235\230\353\217\204\354\213\234\354\260\276\352\270\260.py" @@ -0,0 +1,40 @@ +import sys +from collections import deque + +input = sys.stdin.readline + +def bfs(start): + global k + queue = deque([start]) + visited[start] = 0 # 시작 노드의 거리를 0으로 설정 + while queue: + node = queue.popleft() + for connected_node in graph[node]: # 해당 노드와 연결된 노드 순회 + if visited[connected_node] == -1: # 방문하지 않은 노드일 경우 + queue.append(connected_node) # 큐에 추가하고 + visited[connected_node] = visited[node] + 1 # 거리를 1 증가 + + # 연결된 노드의 거리가 k와 같다면 answer 리스트에 추가 + if visited[connected_node] == k: + answer.append(connected_node) + return answer + +# 도시 개수 n, 도로 개수 m, 거리 정보 k, 출발도시 번호 x +n, m, k, x = map(int, input().strip().split()) +visited = [-1 for _ in range(n + 1)] # 모든 노드를 -1로 초기화 (방문하지 않은 상태) +graph = [[] for _ in range(n + 1)] +answer = [] + +# 그래프 연결 +for _ in range(m): + u, v = map(int, input().strip().split()) + graph[u].append(v) + +# BFS 호출 -> 출발도시 번호 x로 시작 +answer = bfs(x) +if not answer: + print(-1) +else: + answer.sort() + for u in answer: + print(u) \ No newline at end of file diff --git "a/minjeong/DFSBFS/2024-07-27-[\353\260\261\354\244\200]-#14940-\354\211\254\354\232\264\354\265\234\353\213\250\352\261\260\353\246\254.py" "b/minjeong/DFSBFS/2024-07-27-[\353\260\261\354\244\200]-#14940-\354\211\254\354\232\264\354\265\234\353\213\250\352\261\260\353\246\254.py" new file mode 100644 index 00000000..9672e0c5 --- /dev/null +++ "b/minjeong/DFSBFS/2024-07-27-[\353\260\261\354\244\200]-#14940-\354\211\254\354\232\264\354\265\234\353\213\250\352\261\260\353\246\254.py" @@ -0,0 +1,47 @@ +import sys +from collections import deque +input = sys.stdin.readline + +# 목표지점까지의 거리 구하기 +def find_distance_to_goal(n, m, grid): + # 거리배열(모든 지점에 대한 거리를 저장) + distances = [[-1 for _ in range(m)] for _ in range(n)] + + # 목표지점 찾기 + for i in range(n): + for j in range(m): + if grid[i][j] == 2: # 목표지점의 위치 저장하고, 0으로 설정 + target_x = i + target_y = j + distances[i][j] = 0 + if grid[i][j] == 0: # 땅이 아닌 곳이므로 0으로 설정 + distances[i][j] = 0 + + queue = deque([(target_x, target_y)]) # 큐 초기화 + directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # 방향 리스트 + + # BFS 탐색 + while queue: + x, y = queue.popleft() # 현재지점 pop + for dx, dy in directions: + nx, ny = x + dx, y + dy # 현재 지점에서 상하좌우 인접한 지점 + # 인접한 지점이 지도의 범위 안에 있고, 갈 수 있는 땅(값이 1)이며, 아직 방문하지 않은 지점이라면: + if (0 <= nx < n and 0 <= ny < m) and grid[nx][ny] == 1 and distances[nx][ny] == -1: + distances[nx][ny] = distances[x][y] + 1 # 인접한 지점의 거리를 현재 지점의 거리 + 1로 설정 + queue.append((nx, ny)) # 인접한 지점을 큐에 추가 + + return distances + +# 초기화 +n, m = map(int, input().split()) # n: 세로, m: 가로 +grid = [] # 지도 +for _ in range(n): + line = list(map(int, input().split())) + grid.append(line) + +# 함수 호출 +distances = find_distance_to_goal(n, m, grid) + +# 정답 출력 +for d in distances: + print(" ".join(map(str, d))) # 공백을 구분하여 출력 diff --git "a/minjeong/DFSBFS/2024-07-29-[\353\260\261\354\244\200]-#18405-\352\262\275\354\237\201\354\240\201\354\240\204\354\227\274.py" "b/minjeong/DFSBFS/2024-07-29-[\353\260\261\354\244\200]-#18405-\352\262\275\354\237\201\354\240\201\354\240\204\354\227\274.py" new file mode 100644 index 00000000..7cc2149c --- /dev/null +++ "b/minjeong/DFSBFS/2024-07-29-[\353\260\261\354\244\200]-#18405-\352\262\275\354\237\201\354\240\201\354\240\204\354\227\274.py" @@ -0,0 +1,43 @@ +import sys +from collections import deque +input = sys.stdin.readline + +def get_result(goal_sec, goal_x, goal_y, grid, n, k): + virus_info = [] # 바이러스 정보를 담는 리스트 초기화 + + # 시험관을 순회하며 바이러스 팀섹 + for i in range(n): + for j in range(n): + if grid[i][j] != 0: # 바이러스라면 + virus_info.append((grid[i][j], 0, i, j)) # 바이러스 번호, 현재 시간, x좌표, y좌표를 추가 + + virus_info.sort() # 바이러스 정보 리스트를 오름차순으로 정렬 + queue = deque(virus_info) # 큐 초기화 + directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # 방향 리스트 (상, 하, 좌, 우) + + while queue: + virus_num, time, x, y = queue.popleft() + + # 목표 시간에 도달하면 종료 + if time == goal_sec: + break + + for dx, dy in directions: + nx, ny = x + dx, y + dy # 현재 지점에서 상하좌우 인접한 지점 + # 시험관 범위 안에 있고 아직 바이러스가 없는 경우 현재의 바이러스를 전파 + if (0 <= nx < n and 0 <= ny < n) and grid[nx][ny] == 0: + grid[nx][ny] = virus_num + queue.append((virus_num, time + 1, nx, ny)) + + return grid[goal_x][goal_y] + +# 입력 처리 +n, k = map(int, input().split()) # n: 시험관 크기 / k: 바이러스 개수 +grid = [] # 시험관 정보 +for _ in range(n): + li = list(map(int, input().split())) + grid.append(li) +s, x, y = map(int, input().split()) # 시간, x좌표, y좌표 + +# 함수 호출 및 결과 출력 +print(get_result(s, x-1, y-1, grid, n, k)) diff --git "a/minjeong/DynamicProgramming/2024-07-26-[\353\260\261\354\244\200]-#9184-\354\213\240\353\202\230\353\212\224\355\225\250\354\210\230\354\213\244\355\226\211.py" "b/minjeong/DynamicProgramming/2024-07-26-[\353\260\261\354\244\200]-#9184-\354\213\240\353\202\230\353\212\224\355\225\250\354\210\230\354\213\244\355\226\211.py" new file mode 100644 index 00000000..02e46b01 --- /dev/null +++ "b/minjeong/DynamicProgramming/2024-07-26-[\353\260\261\354\244\200]-#9184-\354\213\240\353\202\230\353\212\224\355\225\250\354\210\230\354\213\244\355\226\211.py" @@ -0,0 +1,23 @@ +import sys +input = sys.stdin.readline + +def w(a, b, c): + if (a, b, c) in memo: + return memo[(a, b, c)] + if a <= 0 or b <= 0 or c <= 0: + memo[(a, b, c)] = 1 + return 1 + elif a > 20 or b > 20 or c > 20: + memo[(a, b, c)] = w(20, 20, 20) + elif a < b and b < c: + memo[(a, b, c)] = w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c) + else: + memo[(a, b, c)] = w(a - 1, b, c) + w(a - 1, b - 1, c) + w(a - 1, b, c - 1) - w(a - 1, b - 1, c - 1) + return memo[(a, b, c)] + +memo = {} +while True: + a, b, c = map(int, input().split()) + if a == -1 and b == -1 and c == -1: + break + print('w(%d, %d, %d) = %d' % (a, b, c, w(a, b, c))) \ No newline at end of file diff --git "a/minjeong/Greedy/2024-07-26-[\353\260\261\354\244\200]-#13305-\354\243\274\354\234\240\354\206\214.py" "b/minjeong/Greedy/2024-07-26-[\353\260\261\354\244\200]-#13305-\354\243\274\354\234\240\354\206\214.py" new file mode 100644 index 00000000..7c2b8ae6 --- /dev/null +++ "b/minjeong/Greedy/2024-07-26-[\353\260\261\354\244\200]-#13305-\354\243\274\354\234\240\354\206\214.py" @@ -0,0 +1,18 @@ +import sys +input = sys.stdin.readline + +# 초기화 +n = int(input()) # n: 도시의 개수 +road = list(map(int, input().split())) # 도로의 길이 +oil_price = list(map(int, input().split())) # 리터당 가격 + +min_cost = 0 # 최저 비용 +min_price = oil_price[0] # 첫번째 도시의 기름 가격 + +for i in range(n - 1): + if oil_price[i] < min_price: # 현재 도시에서의 기름 가격이 최소 가격보다 작으면 갱신 + min_price = oil_price[i] + min_cost += min_price * road[i] # 현재 도시에서 다음 도시로 이동할 때 드는 비용을 추가 + +print(min_cost) + diff --git "a/minjeong/Math/2024-07-27-[\353\260\261\354\244\200]-#30802-\354\233\260\354\273\264\355\202\244\355\212\270.py" "b/minjeong/Math/2024-07-27-[\353\260\261\354\244\200]-#30802-\354\233\260\354\273\264\355\202\244\355\212\270.py" new file mode 100644 index 00000000..c05e2508 --- /dev/null +++ "b/minjeong/Math/2024-07-27-[\353\260\261\354\244\200]-#30802-\354\233\260\354\273\264\355\202\244\355\212\270.py" @@ -0,0 +1,16 @@ +import sys +from math import ceil +input = sys.stdin.readline + +n = int(input()) # 참가자 수 +sizes = list(map(int, input().split())) # 티셔츠사이즈별 신청자 수(S, M, L, XL, XXL, XXXL) +t, p = map(int, input().split()) # t: 티셔츠 묶음 수, p: 펜 묶음 수 + +# t장씩 최소 몇 묶음 주문해야 하는지 계산 +min_t_shirts = 0 +for s in sizes: + min_t_shirts += ceil(s / t) +print(min_t_shirts) + +# p자루씩 최대 몇 묶음 주문할 수 있는지와, 그 때 펜을 한 자루씩 몇 개 주문하는지 계산 +print(n // p, n % p) diff --git "a/minjeong/Math/2024-07-27-[\353\260\261\354\244\200]-#31403-A+B-C.py" "b/minjeong/Math/2024-07-27-[\353\260\261\354\244\200]-#31403-A+B-C.py" new file mode 100644 index 00000000..4b182fda --- /dev/null +++ "b/minjeong/Math/2024-07-27-[\353\260\261\354\244\200]-#31403-A+B-C.py" @@ -0,0 +1,10 @@ +import sys +from math import ceil +input = sys.stdin.readline + +a = int(input()) +b = int(input()) +c = int(input()) + +print(a + b - c) +print(int(str(a)+str(b))-c) \ No newline at end of file diff --git "a/minjeong/String/2024-07-27-[\353\260\261\354\244\200]-#28702-FizzBuzz.py" "b/minjeong/String/2024-07-27-[\353\260\261\354\244\200]-#28702-FizzBuzz.py" new file mode 100644 index 00000000..9d0218bc --- /dev/null +++ "b/minjeong/String/2024-07-27-[\353\260\261\354\244\200]-#28702-FizzBuzz.py" @@ -0,0 +1,25 @@ +import sys +from math import ceil +input = sys.stdin.readline + +# FizzBuzz 문자열 배열 +fizzbuzz = [0] * 3 +for i in range(3): + fizzbuzz[i] = input().strip() + +for s in fizzbuzz: + if s.isdigit(): # 문자열이 숫자로 이루어져있다면, + idx = fizzbuzz.index(s) # 해당 문자열의 위치를 저장하여 + answer = int(fizzbuzz[idx]) + (3 - idx) # 정답 값을 구하기 + +# FizzBuzz 규칙에 따라 정답 출력 +if answer % 3 == 0 and answer % 5 == 0: + print("FizzBuzz") +elif answer % 3 == 0: + print("Fizz") +elif answer % 5 == 0: + print("Buzz") +else: + print(answer) + +