-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1064.cpp
More file actions
61 lines (51 loc) · 1.26 KB
/
1064.cpp
File metadata and controls
61 lines (51 loc) · 1.26 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 1064. 평행사변형
// 2022.03.06
// 기하학
#include<iostream>
#include<cmath>
using namespace std;
double GetDist(double x1, double y1, double x2, double y2)
{
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
double max3(double a, double b, double c)
{
return max(a, max(b, c));
}
double min3(double a, double b, double c)
{
return min(a, min(b, c));
}
int main()
{
double xa, ya, xb, yb, xc, yc;
cin >> xa >> ya >> xb >> yb >> xc >> yc;
double m1 = 987654321;
double m2 = 987654321;
if (xa != xb)
{
m1 = abs(yb - ya) / abs(xb - xa);
}
if (xb != xc)
{
m2 = abs(yc - yb) / abs(xc - xb);
}
// 점 3개가 한 직선에 있는 경우
if (m1 == m2)
{
cout << -1 << '\n';
return 0;
}
// 3개의 변
double d1 = GetDist(xa, ya, xb, yb);
double d2 = GetDist(xa, ya, xc, yc);
double d3 = GetDist(xb, yb, xc, yc);
// 3개 변 중 2개를 골라서 평행 사변형을 만들었을 때 둘레의 길이
double round1 = 2 * (d1 + d2);
double round2 = 2 * (d2 + d3);
double round3 = 2 * (d3 + d1);
cout << fixed;
cout.precision(10);
cout << max3(round1, round2, round3) - min3(round1, round2, round3) << endl;
return 0;
}