-
Notifications
You must be signed in to change notification settings - Fork 8
/
#1040 矩形判断(计算几何).cpp
79 lines (67 loc) · 1.18 KB
/
#1040 矩形判断(计算几何).cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include"iostream"
using namespace std;
struct Point{
int x, y;
};
struct Line{
Point p1, p2;
};
bool judgePoint(Line *l)
{
Point tag[4];
int taga[4] = { 0 };
for (int i = 0; i < 4; i++)
{
tag[i] = l[0].p1;
for (int j = 0; j < 4; j++)
{
if ((tag[i].x == l[j].p1.x &&tag[i].y == l[j].p1.y) || (tag[i].x == l[j].p2.x &&tag[i].y == l[j].p2.y))
taga[i]++;
}
}
bool flag = false;
for (int i = 0; i < 4; i++)
{
if (taga[i] == 2)
flag = true;
else
{
flag = false;
break;
}
}
return flag;
}
bool judgeLine(Line *l)
{
for (int i = 1; i<4; ++i)
{
//判断是不是垂直
if ((l[0].p1.y - l[0].p2.y)*(l[i].p1.y - l[i].p2.y) == -(l[0].p1.x - l[0].p2.x)*(l[i].p1.x - l[i].p2.x))
continue;
//判断是不是平行
if ((l[0].p1.y - l[0].p2.y)*(l[i].p1.x - l[i].p2.x) == (l[0].p1.x - l[0].p2.x)*(l[i].p1.y - l[i].p2.y))
continue;
return false;
}
return true;
}
int main()
{
int n;
Line l[4];
cin >> n;
while (n--)
{
for (int i = 0; i < 4; i++)
{
cin >> l[i].p1.x >> l[i].p1.y >> l[i].p2.x >> l[i].p2.y;
}
if (judgePoint(l) && judgeLine(l))
cout << "YES"<<endl;
else
cout << "NO"<<endl;
}
system("pause");
return 0;
}