Skip to content

Commit

Permalink
Update 036.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed May 5, 2022
1 parent 19cf55d commit 9dcb95a
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions 036.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,33 @@
```cpp
#include <iostream>
#include <vector>
#include <limits> // std::numeric_limits<>
#include <algorithm> // std::min(), std::max()
#include <algorithm> // std::minmax_element()
#include <cmath> // std::abs()

struct Point
{
long long x, y;
};

int main()
{
// N 個の点, Q 個のクエリ
int N, Q;
std::cin >> N >> Q;

std::vector<Point> P(N);
for (auto& p : P)
std::vector<long long> Xs(N), Ys(N);
for (int i = 0; i < N; ++i)
{
long long X, Y;
std::cin >> X >> Y;

// 45 度の回転(√2 倍の拡大を伴う)
p.x = (X - Y);
p.y = (X + Y);
Xs[i] = (X - Y);
Ys[i] = (X + Y);
}

// 各軸における最小値と最大値を求める
long long minX = std::numeric_limits<long long>::max();
long long maxX = std::numeric_limits<long long>::lowest();
long long minY = std::numeric_limits<long long>::max();
long long maxY = std::numeric_limits<long long>::lowest();
for (auto& p : P)
{
minX = std::min(minX, p.x);
maxX = std::max(maxX, p.x);
minY = std::min(minY, p.y);
maxY = std::max(maxY, p.y);
}
const auto xp = std::minmax_element(Xs.begin(), Xs.end()); // イテレータのペアを返す
const auto yp = std::minmax_element(Ys.begin(), Ys.end());
const auto xMin = *xp.first;
const auto xMax = *xp.second;
const auto yMin = *yp.first;
const auto yMax = *yp.second;

// 各クエリについて
for (int i = 0; i < Q; ++i)
Expand All @@ -52,11 +41,12 @@ int main()
--T;

// チェビシェフ距離の最大値を求める
const Point p = P[T];
const long long a = std::abs(p.x - minX);
const long long b = std::abs(p.x - maxX);
const long long c = std::abs(p.y - minY);
const long long d = std::abs(p.y - maxY);
const auto x = Xs[T];
const auto y = Ys[T];
const auto a = std::abs(x - xMin);
const auto b = std::abs(x - xMax);
const auto c = std::abs(y - yMin);
const auto d = std::abs(y - yMax);

std::cout << std::max({ a, b, c, d }) << '\n';
}
Expand Down

0 comments on commit 9dcb95a

Please sign in to comment.