Advertisement
Mirbek

ТҮЗӨТҮҮ

Jan 18th, 2022
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     ios::sync_with_stdio(0);
  7.  
  8.     int x[3], y[3];
  9.     cin >> x[0] >> y[0];
  10.     cin >> x[1] >> y[1];
  11.     cin >> x[2] >> y[2];
  12.  
  13.     sort(x, x + 3);
  14.     sort(y, y + 3);
  15.  
  16.     int ans = 1e9;
  17.  
  18.     for (int i = 1; i <= 2021; i++) {
  19.         int ret = 0;
  20.         ret += abs(i - x[0]);
  21.         ret += abs(i - x[1]);
  22.         ret += abs(i - x[2]);
  23.  
  24.         if (y[0] == y[2]) {
  25.             ret += 2;
  26.         } else if (y[0] == y[1] || y[1] == y[2]) {
  27.             ret++;
  28.         }
  29.  
  30.         ans = min(ans, ret);
  31.     }
  32.     for (int i = 1; i <= 2021; i++) {
  33.         int ret = 0;
  34.         ret += abs(i - y[0]);
  35.         ret += abs(i - y[1]);
  36.         ret += abs(i - y[2]);
  37.  
  38.         if (x[0] == x[2]) {
  39.             ret += 2;
  40.         } else if (x[0] == x[1] || x[1] == x[2]) {
  41.             ret++;
  42.         }
  43.  
  44.         ans = min(ans, ret);
  45.     }
  46.  
  47.     cout << ans << endl;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement