Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed May 5, 2022
1 parent db56b28 commit 19cf55d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
64 changes: 64 additions & 0 deletions 036.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 036 - Max Manhattan Distance (★5)

## 解答

```cpp
#include <iostream>
#include <vector>
#include <limits> // std::numeric_limits<>
#include <algorithm> // std::min(), std::max()
#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)
{
long long X, Y;
std::cin >> X >> Y;

// 45 度の回転(√2 倍の拡大を伴う)
p.x = (X - Y);
p.y = (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);
}

// 各クエリについて
for (int i = 0; i < Q; ++i)
{
int T;
std::cin >> T;
--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);

std::cout << std::max({ a, b, c, d }) << '\n';
}
}
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ C++17 標準ライブラリの機能を優先して使い、競技プログラ
|021| | | | |
|[029](https://atcoder.jp/contests/typical90/tasks/typical90_ac)|[Long Bricks](./029.md)|★5|(1) [👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/029-01.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/029-01.cpp),[📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/029-02.cpp)<br>(2) [👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/029-02.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/029-03.cpp)|(解法 1) 「座標圧縮」で効率化<br>(解法 2) 区間に対する処理は「セグメント木」|
|030| | | | |
|036| | | | |
|[036](https://atcoder.jp/contests/typical90/tasks/typical90_aj)|[Max Manhattan Distance](./036.md)|★5|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/036.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/036.cpp)|マンハッタン距離は 45 度回転|
|[037](https://atcoder.jp/contests/typical90/tasks/typical90_ak)|[Don't Leave the Spice](./037.md)|★5|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/037.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/037.cpp)|DP をセグメント木で高速化|
|039| | | | |
|051| | | | |
Expand Down

0 comments on commit 19cf55d

Please sign in to comment.