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

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

Hi guys, Looking codes of reds after contests, i was very curious, because they use random_shuffle() on many cases. But i do not know good aplications for this function.

Can somebody help me with some problems and aplications that is easy solveable with random_shuffle()?

thanks for advice :D

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

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

Sometimes you can write a solution that works great for random data, but fails on some several specific test cases. Using random_shuffle kinda eliminates such cases by making data order random. For example quick sort works like that. There can be test when it will work in O(n^2) time, but random_shuffles almost ensures that it's O(n * log(n)). Maybe there are other usecases, but idk about them.

  • »
    »
    10 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    By the way, how to prove that standard quicksort implementation that uses an a[(l + r) / 2] element as a pivot works in expected time if we apply random_shuffle to the array?

    It is a well-known exercise to prove that quicksort with pivot uniformly chosen at random works in expected time but I never heard about proving the same statement for a deterministic quicksort after shuffling at random.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

How was random shuffle used in 358 div2 . E?we needed to calculate triangle with maximum area ,how random shuffle helps in doing that.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

https://www.youtube.com/watch?v=lR-eLHSqAaA

The main idea is that after shuffling the input you can be sure that the order cannot be 'bad' (like in qsort example above).

Sometimes (like in video) it can result in improving complexity.