Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 프로그래머스
- leetcode
- wandb
- GCP
- FDS
- Matplotlib
- torchserve
- Kaggle
- 코딩테스트
- GIT
- 백준
- GitHub Action
- 완전탐색
- Kubernetes
- pytorch
- DeepLearning
- autoencoder
- NaverAItech
- 알고리즘
- pep8
- PytorchLightning
- github
- python
- vscode
- rnn
- datascience
- 네이버AItech
- NLP
- FastAPI
- docker
Archives
- Today
- Total
Sangmun
백준 15686번 치킨 배달 본문
https://www.acmicpc.net/problem/15686
15686번: 치킨 배달
크기가 N×N인 도시가 있다. 도시는 1×1크기의 칸으로 나누어져 있다. 도시의 각 칸은 빈 칸, 치킨집, 집 중 하나이다. 도시의 칸은 (r, c)와 같은 형태로 나타내고, r행 c열 또는 위에서부터 r번째 칸
www.acmicpc.net
단순히 브루트 포스로 해결이 되는 문제이다...
import sys
from itertools import combinations
input = sys.stdin.readline
N, M = map(int,input().split())
matrix = [list(map(int,input().split())) for _ in range(N)]
house_position = []
chicken_position = []
for idx1, row in enumerate(matrix):
for idx2, k in enumerate(row):
if k == 1:
house_position.append((idx1,idx2))
if k == 2:
chicken_position.append((idx1,idx2))
chicken_comb = list(combinations(chicken_position, M))
final_result = []
for each0 in chicken_comb:
chicken_distance = []
for each1 in house_position:
tmp = []
for each2 in each0:
tmp.append(abs(each1[0] - each2[0]) + abs(each1[1] - each2[1]))
chicken_distance.append(min(tmp))
final_result.append(sum(chicken_distance))
print(min(final_result))
'알고리즘 > 백준' 카테고리의 다른 글
| 백준 12851번 숨바꼭질2 (0) | 2022.12.14 |
|---|---|
| 백준 2096번 내려가기 (0) | 2022.12.12 |
| 백준 14938번 서강그라운드 (0) | 2022.12.10 |
| 백준 16953번 A -> B (0) | 2022.12.08 |
| 백준 1094번 막대기 (0) | 2022.12.07 |
Comments