Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed May 4, 2022
1 parent d3c91f2 commit c8458c4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
59 changes: 59 additions & 0 deletions 066.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 066 - Various Arrays (★5)

## 解答

```cpp
#include <iostream> // std::fixed
#include <vector>
#include <iomanip> // std::setprecision

double CalcExpected(int L0, int R0, int L1, int R1)
{
// 転倒数の個数
int count = 0;

// i: 現在の値
for (int i = L0; i <= R0; ++i)
{
// k: 次の値
for (int k = L1; k <= R1; ++k)
{
if (i > k)
{
++count;
}
}
}

// 期待値を返す
return static_cast<double>(count) / ((R0 - L0 + 1) * (R1 - L1 + 1));
}

int main()
{
// 長さ N の数列
int N;
std::cin >> N;

// 数列の各要素は L[i] 以上 R[i] 以下のランダムな整数
std::vector<int> L(N), R(N);
for (int i = 0; i < N; ++i)
{
std::cin >> L[i] >> R[i];
}

// 期待値の合計
double result = 0.0;

for (int i = 0; i < N; ++i)
{
for (int k = i + 1; k < N; ++k)
{
result += CalcExpected(L[i], R[i], L[k], R[k]);
}
}

// 小数点以下 10 桁まで表示
std::cout << std::fixed << std::setprecision(10) << result << '\n';
}
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ C++17 標準ライブラリの機能を優先して使い、競技プログラ
|051| | | | |
|056| | | | |
|060| | | | |
|066| | | | |
|[066](https://atcoder.jp/contests/typical90/tasks/typical90_bn)|[Various Arrays](./066.md)|★5|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/066.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/066a.cpp),[📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/066b.cpp)|期待値の線形性|
|068| | | | |
|073| | | | |
|081| | | | |
Expand Down

0 comments on commit c8458c4

Please sign in to comment.