x と y の差のそれぞれが何パターン出現するかを計算して答えを出す。
class Pillars { public: double getExpectedLength(int w, int x, int y) { if (x < y) ; else swap(x, y); double sum = x * w; lli cnt = x; for (lli h = 1; h <= y - 1; ++h) { lli n = min((lli)x, y - h); cnt += n; sum += hypot(w, h) * n; } for (lli h = 1; h <= x - 1; ++h) { lli n = max(0LL, x - h); cnt += n; sum += hypot(w, h) * n; } return sum / cnt; } };