-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1485.cpp
More file actions
50 lines (45 loc) · 961 Bytes
/
1485.cpp
File metadata and controls
50 lines (45 loc) · 961 Bytes
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
// 1485. 정사각형
// 2019.08.23
// 수학
#include<iostream>
#include<algorithm>
using namespace std;
int x[4];
int y[4];
int dist[12];
int main()
{
int n;
cin >> n;
while (n-- > 0)
{
for (int i = 0; i < 4; i++)
{
cin >> x[i] >> y[i];
}
int cnt = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (i != j)
{
dist[cnt++] = (x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]);
}
}
}
// 정렬하면 4변의 길이가 2번씩 차례대로 나오고 대각선의 길이 2개가 2번씩 차례대로 나온다.
sort(dist, dist + 12);
// 변의 길이 중 맨처음과 맨 마지막이 같다면 정렬된 상태이므로 네 변의 길이는 모두 같다.
// 변의 길이가 모두 같고 두 대각선의 길이가 같다면 정사각형이다.
if (dist[0] == dist[6] && dist[8] == dist[10])
{
cout << 1 << endl;
}
else
{
cout << 0 << endl;
}
}
return 0;
}