Блог пользователя Virtual_Contestant

Автор Virtual_Contestant, история, 6 лет назад, По-английски

Hello everyone, Can anyone just confirm how the graph of cost and the final height (same for all) would look like in this question? What I think is it would be unimodal function (having exactly one minima) but i don't know if it is correct. please tell me so i can edit. i just wanted to know just how graph of total cost for modifying all sticks to some particular same height would look like w.r.t to that height. please please help me https://cses.fi/problemset/task/1074

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +11 Проголосовать: не нравится

Lets take an example of 3 sticks only:

$$$cost(x) = |x-x_0| + |x-x_1| + |x-x_2| $$$

Lets try to visualise how our cost function will change when x goes from $$$(-\infty, +\infty)$$$

$$$ \gt $$$ denotes increasing

$$$ \lt $$$ denotes decreasing

Range $$$x$$$ $$$|x-x_0|$$$ $$$|x-x_1|$$$ $$$|x-x_2|$$$
$$$(-\infty, x_0)$$$ $$$ \lt $$$ $$$ \lt $$$ $$$ \lt $$$
$$$(x_0, x_1)$$$ $$$ \gt $$$ $$$ \lt $$$ $$$ \lt $$$
$$$(x_1, x_2)$$$ $$$ \gt $$$ $$$ \gt $$$ $$$ \lt $$$
$$$(x_2, \infty)$$$ $$$ \gt $$$ $$$ \gt $$$ $$$ \gt $$$
  • We see that in every interval,
    (number of increasing functions) $$$ \gt =$$$ (number of inc functions in previous interval)
  • Also, rate of increase for each function is also same (unit for every unit change of x)
  • So the overall cost function decreases till count of decreasing functions > count of increasing functions, eventually hits a minima when counts become equal and then starts increasing again. Hence, $$$unimodal$$$.