Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Jul 23, 2022
1 parent 17ac52b commit d625117
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions 070.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 070 - Plant Planning (★4)

## 解答

```cpp
#include <iostream>
#include <vector>
#include <algorithm> // std::nth_element()
#include <cmath> // std::abs()

int main()
{
// N 棟の工場
int N;
std::cin >> N;

std::vector<int> X(N), Y(N);
for (int i = 0; i < N; ++i)
{
std::cin >> X[i] >> Y[i];
}

// 中央値を求める
// 参考: https://zenn.dev/reputeless/books/standard-cpp-for-competitive-programming/viewer/library-algorithm#4.4-n-%E7%95%AA%E7%9B%AE%E3%81%AB%E5%B0%8F%E3%81%95%E3%81%84%E8%A6%81%E7%B4%A0%E3%82%92%E6%B1%82%E3%82%81%E3%82%8B
std::nth_element(X.begin(), (X.begin() + N / 2), X.end());
std::nth_element(Y.begin(), (Y.begin() + N / 2), Y.end());

const int xMedian = X[N / 2];
const int yMedian = Y[N / 2];

long long ans = 0;

for (int i = 0; i < N; ++i)
{
ans += std::abs(X[i] - xMedian);
ans += std::abs(Y[i] - yMedian);
}

std::cout << ans << '\n';
}
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ C++17 標準ライブラリの機能を優先して使い、競技プログラ
|[043](https://atcoder.jp/contests/typical90/tasks/typical90_aq)|[Maze Challenge with Lack of Sleep](./043.md)|★4|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/043.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/043.cpp)|拡張 BFS・ダイクストラ|
|[058](https://atcoder.jp/contests/typical90/tasks/typical90_bf)|[Original Calculator](./058.md)|★4|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/058.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/058.cpp)|周期性を考える|
|[063](https://atcoder.jp/contests/typical90/tasks/typical90_bk)|[Monochromatic Subgrid](./063.md)|★4|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/063.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/063.cpp)|変な制約に着目する / 状態数が少ない変量を全探索|
|070| | | | |
|[070](https://atcoder.jp/contests/typical90/tasks/typical90_br)|[Plant Planning](./070.md)|★4|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/070.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/070.cpp)|x, y 独立に考える|
|072| | | | |
|085| | | | |

Expand Down

0 comments on commit d625117

Please sign in to comment.