Skip to content

Commit f475443

Browse files
committed
[Silver V] Title: 유미, Time: 0 ms, Memory: 2032 KB -BaekjoonHub
1 parent 77a58af commit f475443

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# [Silver V] 유미 - 17286
2+
3+
[문제 링크](https://www.acmicpc.net/problem/17286)
4+
5+
### 성능 요약
6+
7+
메모리: 2032 KB, 시간: 0 ms
8+
9+
### 분류
10+
11+
브루트포스 알고리즘, 기하학, 피타고라스 정리
12+
13+
### 제출 일자
14+
15+
2025년 2월 4일 11:33:36
16+
17+
### 문제 설명
18+
19+
<p>매달리기를 좋아하는 고양이 유미와 세 사람은 이차원 좌표평면 위에 있다. 좌표평면 상의 좌표는 (x, y)로 나타낼 수 있다. 유미는 세 사람 모두에게 안기려고 한다. 유미가 사람에게 안기려면 사람이 있는 위치로 이동해야 한다. 사람은 이동하지 않는다. 귀찮은 유미는 최단 거리로 세 사람에게 이동하려고 한다.</p>
20+
21+
<p>예를 들어, 유미의 위치가 (0, 0) 세 사람의 위치가 각각 (1, 0), (2, 0), (4, 0)인 경우에, (0, 0) → (1, 0) → (2, 0) → (4, 0)으로 이동하면 최단 거리로 이동할 수 있다. 이때, 거리는 1 + 1 + 2 = 4이다.</p>
22+
23+
<p>유미와 세 사람의 위치가 주어진다. 세 사람 모두에게 안기는 최단 거리를 구하시오.</p>
24+
25+
### 입력
26+
27+
<p>첫째 줄에 유미의 위치, 둘째 줄부터 세 개의 줄에 사람의 위치가 한 줄에 하나씩 주어진다. 위치는 x, y좌표의 순서로 주어지며, 공백으로 구분되어져 있다. (-10 ≤ x, y ≤ 10)</p>
28+
29+
<p>한 위치에 둘 이상의 사람이 있는 경우는 없고, 유미와 사람의 위치가 같은 경우도 없다.</p>
30+
31+
### 출력
32+
33+
<p>첫째 줄에 유미의 최단 거리를 출력한다. 소수점 이하는 버리고 정수만 출력한다.</p>
34+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <vector>
4+
#include <cmath>
5+
6+
using namespace std;
7+
8+
struct Point {
9+
int x, y;
10+
};
11+
12+
double calcDist(const Point &a, const Point &b) {
13+
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
14+
}
15+
16+
int main() {
17+
Point yumi;
18+
cin >> yumi.x >> yumi.y;
19+
20+
vector<Point> persons(3);
21+
for (int i = 0; i < 3; i++) {
22+
cin >> persons[i].x >> persons[i].y;
23+
}
24+
25+
vector<int> perm;
26+
perm.push_back(0);
27+
perm.push_back(1);
28+
perm.push_back(2);
29+
30+
double minDistance = 1e9;
31+
32+
do {
33+
double distSum = 0.0;
34+
distSum += calcDist(yumi, persons[perm[0]]);
35+
distSum += calcDist(persons[perm[0]], persons[perm[1]]);
36+
distSum += calcDist(persons[perm[1]], persons[perm[2]]);
37+
38+
if (distSum < minDistance) {
39+
minDistance = distSum;
40+
}
41+
} while (next_permutation(perm.begin(), perm.end()));
42+
43+
cout << static_cast<int>(minDistance) << "\n";
44+
45+
return 0;
46+
}

0 commit comments

Comments
 (0)