Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_map>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct Point{
- int x, y;
- };
- Point* GetPoints(int n) {
- Point* p = new Point [n];
- for (int i = 0; i < n; ++i) {
- cin >> p[i].x >> p[i].y;
- }
- return p;
- }
- bool Check(const vector<int> v) {
- /*if (v.size() == 1) {
- return v[0] == 0;
- }*/
- for (int i = 0; i <= v.size() / 2; i++) {
- if (v[i] + v[v.size() - 1 - i] != 0) {
- return false;
- }
- }
- return true;
- }
- bool HasVerticalSymLine(int n, const Point p[]) {
- if (n == 0) {
- return true;
- }
- int sum_of_x = 0;
- for (int i = 0; i < n; i++) {
- sum_of_x += p[i].x * 2;
- }
- if (sum_of_x % n != 0) {
- return false;
- }
- int possible_axis = sum_of_x / n;
- unordered_map<int, vector<int>> y_to_x;
- for (int i = 0; i < n; i++) {
- y_to_x[p[i].y].push_back(2 * p[i].x - possible_axis);
- }
- for (auto& [y, x_vector] : y_to_x) {
- sort(x_vector.begin(), x_vector.end());
- if (!Check(x_vector)) {
- return false;
- }
- }
- return true;
- }
- int main() {
- //int n = 0;
- //cin >> n;
- //Point* p = GetPoints(n);
- {
- int n = 3;
- Point p[] = {
- {0, 0},
- {1, 1},
- {-1, 1}
- };
- if (HasVerticalSymLine(n, p)) {
- cout << "YES" << endl;
- } else {
- cout << "NO" << endl;
- }
- }
- {
- int n = 4;
- Point p[] = {
- {1, 1},
- {2, 2},
- {1, 2},
- {2, 3}
- };
- if (HasVerticalSymLine(n, p)) {
- cout << "YES" << endl;
- } else {
- cout << "NO" << endl;
- }
- }
- {
- int n = 3;
- Point p[] = {
- {0, 0},
- {0, 99},
- {0, 1}
- };
- if (HasVerticalSymLine(n, p)) {
- cout << "YES" << endl;
- } else {
- cout << "NO" << endl;
- }
- }
- {
- int n = 3;
- Point p[] = {
- {0, 0},
- {0, 0},
- {1, 0 }
- };
- if (HasVerticalSymLine(n, p)) {
- cout << "YES" << endl;
- } else {
- cout << "NO" << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement