-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathmain.cpp
47 lines (42 loc) · 962 Bytes
/
main.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
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
class Solution {
public:
bool isReflected(vector<pair<int, int>>& points) {
unordered_map<int, set<int>> m;
int mx = INT_MIN, mn = INT_MAX;
for (auto p : points) {
mx = max(mx, p.first);
mn = min(mn, p.first);
m[p.first].insert(p.second);
}
double y = (double)(mx + mn) / 2;
for (auto p : points) {
int t = 2 * y - p.first;
if (!m.count(t) || !m[t].count(p.second)) {
return false;
}
}
return true;
}
};
int main() {
Solution sol;
vector<pair<int, int>> points;
points = {{1, 1}, {-1, 1}};
cout << sol.isReflected(points) << endl;
points = {{1, 1}, {-1, -1}};
cout << sol.isReflected(points) << endl;
return 0;
}