Advertisement
goshansmails

Untitled

Mar 6th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. struct Point{
  9.     int x, y;
  10. };
  11.  
  12. Point* GetPoints(int n) {
  13.     Point* p = new Point [n];
  14.     for (int i = 0; i < n; ++i) {
  15.         cin >> p[i].x >> p[i].y;
  16.     }
  17.     return p;
  18. }
  19.  
  20. bool Check(const vector<int> v) {
  21.     /*if (v.size() == 1) {
  22.         return v[0] == 0;
  23.     }*/
  24.     for (int i = 0; i <= v.size() / 2; i++) {
  25.         if (v[i] + v[v.size() - 1 - i] != 0) {
  26.             return false;
  27.         }
  28.     }
  29.     return true;
  30. }
  31.  
  32. bool HasVerticalSymLine(int n, const Point p[]) {
  33.     if (n == 0) {
  34.         return true;
  35.     }
  36.     int sum_of_x = 0;
  37.     for (int i = 0; i < n; i++) {
  38.         sum_of_x += p[i].x * 2;
  39.     }
  40.     if (sum_of_x % n != 0) {
  41.         return false;
  42.     }
  43.     int possible_axis = sum_of_x / n;
  44.     unordered_map<int, vector<int>> y_to_x;
  45.     for (int i = 0; i < n; i++) {
  46.         y_to_x[p[i].y].push_back(2 * p[i].x - possible_axis);
  47.     }
  48.     for (auto& [y, x_vector] : y_to_x) {
  49.         sort(x_vector.begin(), x_vector.end());
  50.         if (!Check(x_vector)) {
  51.             return false;
  52.         }
  53.     }
  54.     return true;
  55. }
  56.  
  57. int main() {
  58.  
  59.     //int n = 0;
  60.     //cin >> n;
  61.     //Point* p = GetPoints(n);
  62.     {
  63.         int n = 3;
  64.         Point p[] = {
  65.                 {0, 0},
  66.                 {1, 1},
  67.                 {-1, 1}
  68.         };
  69.         if (HasVerticalSymLine(n, p)) {
  70.             cout << "YES" << endl;
  71.         } else {
  72.             cout << "NO" << endl;
  73.         }
  74.     }
  75.  
  76.     {
  77.         int n = 4;
  78.         Point p[] = {
  79.                 {1, 1},
  80.                 {2, 2},
  81.                 {1, 2},
  82.                 {2, 3}
  83.         };
  84.         if (HasVerticalSymLine(n, p)) {
  85.             cout << "YES" << endl;
  86.         } else {
  87.             cout << "NO" << endl;
  88.         }
  89.     }
  90.  
  91.     {
  92.         int n = 3;
  93.         Point p[] = {
  94.                 {0, 0},
  95.                 {0, 99},
  96.                 {0, 1}
  97.         };
  98.         if (HasVerticalSymLine(n, p)) {
  99.             cout << "YES" << endl;
  100.         } else {
  101.             cout << "NO" << endl;
  102.         }
  103.     }
  104.  
  105.     {
  106.         int n = 3;
  107.         Point p[] = {
  108.                 {0, 0},
  109.                 {0, 0},
  110.                 {1, 0   }
  111.         };
  112.         if (HasVerticalSymLine(n, p)) {
  113.             cout << "YES" << endl;
  114.         } else {
  115.             cout << "NO" << endl;
  116.         }
  117.     }
  118.     return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement