Dang_Quan_10_Tin

Ngu

Aug 7th, 2021 (edited)
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #define task "SPRESCUE"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. using ll = long long;
  10. using ld = long double;
  11.  
  12. template <class T>
  13. void read(T &x)
  14. {
  15.     x = 0;
  16.     register int c;
  17.     while ((c = getchar()) && (c > '9' || c < '0'))
  18.         ;
  19.     for (; c >= '0' && c <= '9'; c = getchar())
  20.         x = x * 10 + c - '0';
  21. }
  22.  
  23. constexpr int N = 1e5 + 5;
  24. constexpr ll Inf = 1e17;
  25. int n;
  26. int x[N], y[N], z[N];
  27. int ooe;
  28.  
  29. void Read()
  30. {
  31.     //cin >> n;
  32.     read(n);
  33.     for (int i = 1; i <= n; ++i)
  34.     {
  35.         //cin >> x[i] >> y[i] >> z[i];
  36.         read(x[i]);
  37.         read(y[i]);
  38.         read(z[i]);
  39.     }
  40.     x[0] = x[1];
  41.     y[0] = y[1];
  42.     z[0] = z[1];
  43. }
  44.  
  45. bool Check(int p, int q, int r)
  46. {
  47.     if (abs(p % 2) != abs(x[0] % 2))
  48.     {
  49.         ++p;
  50.         ++q;
  51.         ++r;
  52.     }
  53.  
  54.     if (abs(q % 2) != abs(y[0] % 2) || abs(r % 2) != abs(z[0] % 2))
  55.         return false;
  56.     return true;
  57. }
  58.  
  59. ll Get(ll p, ll q, ll r)
  60. {
  61.     return max({abs(x[1] - p), abs(x[n] - p), abs(y[1] - q), abs(y[n] - q), abs(z[1] - r), abs(z[n] - r)});
  62. }
  63.  
  64. void Sub_1()
  65. {
  66.     sort(x + 1, x + n + 1);
  67.     sort(y + 1, y + n + 1);
  68.     sort(z + 1, z + n + 1);
  69.  
  70.     int p = (x[n] + x[1]) / 2,
  71.         q = (y[n] + y[1]) / 2,
  72.         r = (z[n] + z[1]) / 2;
  73.  
  74.     ll ans(Inf);
  75.  
  76.     for (int i = -100; i <= 100; ++i)
  77.         for (int j = -100; j <= 100; ++j)
  78.             for (int t = -100; t <= 100; ++t)
  79.                 if (Check(p + i, q + j, r + t))
  80.                     ans = min(ans, Get(p + i, q + j, r + t));
  81.  
  82.     cout << ans;
  83. }
  84.  
  85. int32_t main()
  86. {
  87.     ios::sync_with_stdio(0);
  88.     cin.tie(0);
  89.     cout.tie(0);
  90.     if (fopen(task ".INP", "r"))
  91.     {
  92.         freopen(task ".INP", "r", stdin);
  93.         freopen(task ".OUT", "w", stdout);
  94.     }
  95.     Read();
  96.     Sub_1();
  97. }
Add Comment
Please, Sign In to add comment