D. Fishes

Codeforces
IDCF912D
Time1000ms
Memory256MB
Difficulty
data structuresgraphsgreedyprobabilitiesshortest paths
English · Original
Chinese · Translation
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size _n_ × _m_, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!). The gift bundle also includes a square scoop of size _r_ × _r_, designed for fishing. If the lower-left corner of the scoop-net is located at cell (_x_, _y_), all fishes inside the square (_x_, _y_)...(_x_ + _r_ - 1, _y_ + _r_ - 1) get caught. Note that the scoop-net should lie completely inside the pond when used. Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release _k_ fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put _k_ fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (_n_ - _r_ + 1)·(_m_ - _r_ + 1) possible positions, the average number of caught fishes is as high as possible. ## Input The only line contains four integers _n_, _m_, _r_, _k_ (1 ≤ _n_, _m_ ≤ 105, 1 ≤ _r_ ≤ _min_(_n_, _m_), 1 ≤ _k_ ≤ _min_(_n_·_m_, 105)). ## Output Print a single number — the maximum possible expected number of caught fishes. You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be _a_, and the jury's answer be _b_. Your answer is considered correct, if . [samples] ## Note In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value. <center>![image](https://espresso.codeforces.com/f1262df2acb0bb62b0c4b246249aae30e7f57252.png)</center>
当格里沙正在与德德莫罗兹庆祝新年时,米沙送给莎莎一个大小为 $n × m$ 的小矩形池塘,被划分为 $1 × 1$ 的格子,每个格子中居住着一只邪恶的小鱼(每个格子至多一只鱼,否则它们会争斗!)。 礼品包中还包括一个大小为 $r × r$ 的正方形渔网,用于捕鱼。如果渔网的左下角位于格子 $(x, y)$,则所有位于正方形区域 $(x, y)...(x + r - 1, y + r - 1)$ 内的鱼都会被捕获。注意,使用渔网时必须完全位于池塘内部。 不幸的是,莎莎捕鱼技术不佳,因此随机抛掷渔网。为了不让莎莎沮丧,米沙决定在空池塘中放入 $k$ 条鱼,使得被捕获鱼的期望数量尽可能高。请帮助米沙!换句话说,将 $k$ 条鱼放入池塘的不同格子中,使得当渔网被随机放置在 $(n - r + 1)·(m - r + 1)$ 个可能位置中的任意一个时,被捕获鱼的平均数量最大化。 仅一行包含四个整数 $n, m, r, k$($1 ≤ n, m ≤ 10^5$,$1 ≤ r ≤ \min(n, m)$,$1 ≤ k ≤ \min(n·m, 10^5)$)。 输出一个数——最大的可能期望捕获鱼数。 你的答案若绝对误差或相对误差不超过 $10^{-9}$,则被视为正确。具体而言,设你的答案为 $a$,标准答案为 $b$,当满足 $\frac{|a - b|}{\max(1, |b|)} \leq 10^{-9}$ 时,你的答案被视为正确。 在第一个例子中,你可以将鱼放在格子 $(2, 1)$、$(2, 2)$、$(2, 3)$。此时,对于渔网的任意四个可能位置(用浅绿色标出),内部鱼的数量均为二,因此期望值也为二。 ## Input 仅一行包含四个整数 $n, m, r, k$($1 ≤ n, m ≤ 10^5$,$1 ≤ r ≤ \min(n, m)$,$1 ≤ k ≤ \min(n·m, 10^5)$)。 ## Output 输出一个数——最大的可能期望捕获鱼数。你的答案若绝对误差或相对误差不超过 $10^{-9}$,则被视为正确。具体而言,设你的答案为 $a$,标准答案为 $b$,当满足 $\frac{|a - b|}{\max(1, |b|)} \leq 10^{-9}$ 时,你的答案被视为正确。 [samples] ## Note 在第一个例子中,你可以将鱼放在格子 $(2, 1)$、$(2, 2)$、$(2, 3)$。此时,对于渔网的任意四个可能位置(用浅绿色标出),内部鱼的数量均为二,因此期望值也为二。
Samples
Input #1
3 3 2 3
Output #1
2.0000000000
Input #2
12 17 9 40
Output #2
32.8333333333
API Response (JSON)
{
  "problem": {
    "name": "D. Fishes",
    "description": {
      "content": "While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size _n_ × _m_, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one f",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF912D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size _n_ × _m_, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one f...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "当格里沙正在与德德莫罗兹庆祝新年时,米沙送给莎莎一个大小为 $n × m$ 的小矩形池塘,被划分为 $1 × 1$ 的格子,每个格子中居住着一只邪恶的小鱼(每个格子至多一只鱼,否则它们会争斗!)。\n\n礼品包中还包括一个大小为 $r × r$ 的正方形渔网,用于捕鱼。如果渔网的左下角位于格子 $(x, y)$,则所有位于正方形区域 $(x, y)...(x + r - 1, y + r - 1)$ ...",
      "is_translate": true,
      "language": "Chinese"
    }
  ]
}
Full JSON Raw Segments