-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrectangle_judgement.cpp
More file actions
87 lines (82 loc) · 2.35 KB
/
rectangle_judgement.cpp
File metadata and controls
87 lines (82 loc) · 2.35 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <map>
using namespace std;
class Solution {
public:
bool judge(vector<pair<int, int>> &points) {
map<pair<int, int>, bool> foo;
for (auto ele : points) {
if (foo.find(ele) == foo.end()) {
foo[ele] = true;
}
}
if (foo.size() != 4) {
return false;
}
vector<pair<int, int>> vecs;
for (int i = 0; i < 8; i += 2) {
auto tmp = getVec(points[i], points[i + 1]);
if (tmp.first == 0 && tmp.second == 0) {
return false;
}
vecs.push_back(tmp);
}
if (vecs[0] == vecs[1]) {
if (vecs[2] == vecs[3]) {
return vecs[0].first * vecs[2].first + vecs[0].second * vecs[2].second == 0;
}
return false;
}
if (vecs[0] == vecs[2]) {
if (vecs[1] == vecs[3]) {
return vecs[0].first * vecs[1].first + vecs[0].second * vecs[1].second == 0;
}
return false;
}
if (vecs[0] == vecs[3]) {
if (vecs[1] == vecs[2]) {
return vecs[0].first * vecs[1].first + vecs[0].second * vecs[1].second == 0;
}
return false;
}
return false;
}
pair<int, int> getVec(pair<int, int> p1, pair<int, int> p2) {
if (p1.first < p2.first) {
return make_pair(p2.first - p1.first, p2.second - p1.second);
}
if (p1.first > p2.first) {
return make_pair(p1.first - p2.first, p1.second - p2.second);
}
if (p1.second < p2.second) {
return make_pair(p2.first - p1.first, p2.second - p1.second);
} else {
return make_pair(p1.first - p2.first, p1.second - p2.second);
}
}
};
int main(int argc, char *argv[]) {
Solution so;
int num;
int x, y;
vector<pair<int, int>> points;
cin >> num;
while (num-- > 0) {
points.clear();
for (int i = 0; i < 8; ++i) {
cin >> x >> y;
points.push_back(make_pair(x, y));
}
bool rst = so.judge(points);
if (rst) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}