Skip to content
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

33-H0ngJu #253

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
| 26์ฐจ์‹œ | 2024.08.24 | ๊ทธ๋ฆฌ๋”” | [์‹ ์ž…์‚ฌ์›](https://www.acmicpc.net/problem/1946) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/237 |
| 27์ฐจ์‹œ | 2024.08.27 | DFS | [ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„](https://www.acmicpc.net/problem/1967) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/240 |
| 28์ฐจ์‹œ | 2024.09.04 | ๋ฒจ๋งŒํฌ๋“œ | [ํƒ€์ž„๋จธ์‹ ](https://www.acmicpc.net/problem/11657) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/244 |
| 29์ฐจ์‹œ | 2024.09.06 | ๊ตฌํ˜„ |[ํ†ฑ๋‹ˆ๋ฐ”ํ€ด](https://www.acmicpc.net/problem/14891) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/245 |
| 29์ฐจ์‹œ | 2024.09.06 | ๊ตฌํ˜„ | [ํ†ฑ๋‹ˆ๋ฐ”ํ€ด](https://www.acmicpc.net/problem/14891) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/245 |
| 30์ฐจ์‹œ | 2024.09.27 | ์ˆ˜ํ•™ | [Fly me to the Alpha Centauri](https://www.acmicpc.net/problem/1011) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/248 |
| 31์ฐจ์‹œ | 2024.10.05 | ์ •๋ ฌ | [์„  ๊ธ‹๊ธฐ](https://www.acmicpc.net/problem/2170) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/249 |
| 31์ฐจ์‹œ | 2024.10.05 | ์ •๋ ฌ | [์„  ๊ธ‹๊ธฐ](https://www.acmicpc.net/problem/2170) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/249 |

| 33์ฐจ์‹œ | 2024.11.08 | ๋ฐฑํŠธ๋ž˜ํ‚น | [๋ณ‘์› ๊ฑฐ๋ฆฌ ์ตœ์†Œํ™”](https://www.codetree.ai/training-field/frequent-problems/problems/min-of-hospital-distance/submissions?page=11&pageSize=5) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/253 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import sys

def input() : return sys.stdin.readline().rstrip()

n, m = map(int, input().split())
hospital = []
person = []
info = [[] for _ in range(n)]

# ์‚ฌ๋žŒ, ๋ณ‘์› ์ •๋ณด ๋ฐ›๊ธฐ
for i in range(n):
info[i].extend(list(map(int, input().split())))
for j in range(n):
if info[i][j] == 2:
hospital.append((i,j))
if info[i][j] == 1:
person.append((i,j))

distance = [[0 for _ in range(len(hospital))] for _ in range(len(person))]

for i in range(len(person)):
px, py = person[i]
for j in range(len(hospital)):
hx, hy = hospital[j]
distance[i][j] = abs(px-hx) + abs(py-hy)

# hospital ์œ„์น˜ ์ค‘์— m๊ฐœ๋ฅผ ์„ ํƒํ•ด์„œ ์ตœ์†Ÿ๊ฐ’ ๊ตฌํ•˜๊ธฐ
hospital_arr = [i for i in range(len(hospital))]
all_combinations = []

def combination(start, depth, combination_arr):
if depth == m: # m๋งŒํผ ์ฐพ์œผ๋ฉด return
all_combinations.append(combination_arr[:])
return
for i in range(start, len(hospital_arr)):
combination_arr.append(hospital_arr[i]) # ์›์†Œ ์ผ๋‹จ ๋„ฃ๊ณ 
combination(i + 1, depth + 1, combination_arr) # ์žฌ๊ท€ ๋Œ๋ฆผ
combination_arr.pop() # ๋‹ค์‹œ ๋ฝ‘์€๊ฑฐ ๋ณต๊ท€ -> [1,2,3]์„ ๊ตฌํ•˜๋ฉด, 3๋นผ๊ณ  ๋‹ค์‹œ ๋‹ค์Œ ๋ฐ˜๋ณต๋ฌธ ๋„ฃ์–ด์„œ [1,2,4] ๊ฐ€๋Šฅ

combination(0, 0, [])

min_distance_sum = 1e9
for hospitals_combination in all_combinations:
cur_distance = 0

for i in range(len(person)):
dist = 1e9
for j in hospitals_combination:
dist = min(dist, distance[i][j])
cur_distance += dist

min_distance_sum = min(min_distance_sum, cur_distance)

print(min_distance_sum)

# --- combination -----

# import sys
# import itertools

# def input() : return sys.stdin.readline().rstrip()

# n, m = map(int, input().split())
# hospital = []
# person = []
# info = [[] for _ in range(n)]

# # ์‚ฌ๋žŒ, ๋ณ‘์› ์ •๋ณด ๋ฐ›๊ธฐ
# for i in range(n):
# info[i].extend(list(map(int, input().split())))
# for j in range(n):
# if info[i][j] == 2:
# hospital.append((i,j))
# if info[i][j] == 1:
# person.append((i,j))

# distance = [[0 for _ in range(len(hospital))] for _ in range(len(person))]

# for i in range(len(person)):
# px, py = person[i]
# for j in range(len(hospital)):
# hx, hy = hospital[j]
# distance[i][j] = abs(px-hx) + abs(py-hy)

# # hospital ์œ„์น˜ ์ค‘์— m๊ฐœ๋ฅผ ์„ ํƒํ•ด์„œ ์ตœ์†Ÿ๊ฐ’ ๊ตฌํ•˜๊ธฐ

# min_distance_sum = 1e9
# combbination_arr = [i for i in range(len(hospital))]

# for hospitals_combination in itertools.combinations(combbination_arr, m):
# cur_distance = 0

# for i in range(len(person)):
# dist = 1e9
# for j in hospitals_combination:
# dist = min(dist, distance[i][j])
# cur_distance += dist

# min_distance_sum = min(min_distance_sum, cur_distance)

# print(min_distance_sum)

# # ๋นˆ์ž๋ฆฌ๋ฉด 0, ์‚ฌ๋žŒ์ด๋ฉด 1, ๋ณ‘์›์ด๋ฉด 2
# # ์ถœ๋ ฅ์€ ์ตœ์†Œ ๊ฑฐ๋ฆฌ

# # ๋ณ‘์›์˜ ์ˆ˜ ๋งŒํผ ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ด์„œ, ๊ฐ ์‚ฌ๋žŒ๋งˆ๋‹ค์˜ ์ตœ์†Œ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค.
# # ๊ฐ ๋ณ‘์›์˜ ๊ฑฐ๋ฆฌ ์ด ํ•ฉ์„ ๊ณ„์‚ฐํ•ด์„œ ์ •๋ ฌํ•œ๋‹ค. -> ๋ฌธ์ œ : ์‚ฌ๋žŒ๋งˆ๋‹ค ๋‹ค๋ฅธ ๋ณ‘์›์ด ์ตœ์†Œ ๊ฑฐ๋ฆฌ์ผ ์ˆ˜ ์žˆ์ง€๋งŒ, ํ•ด๋‹น ๊ฐ€๋Šฅ์„ฑ์„ ๋ฌด์‹œํ•˜๊ฒŒ ๋จ

# # ๊ฐ ์‚ฌ๋žŒ๋งˆ๋‹ค ๊ฐ ๋ณ‘์›์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค.
# # [[1,2,4,5], [1,2,4,5]]์˜ ํ˜•ํƒœ
# # ๋ณ‘์› ์ค‘ m๊ฐœ๋ฅผ ๊ณ ๋ฅด๋Š” ์กฐํ•ฉ
# # ์กฐํ•ฉ์—์„œ ์ตœ์†Œ๊ฑฐ๋ฆฌ ๊ฐฑ์‹ ํ•˜์—ฌ ์ฐพ๊ธฐ
Loading