IOM 2018, Блиц, английски — Задача 42

OLYMPIAD OF METROPOLISES. Moscow, September 3 · 3 септември 2018 г.

Условие

Consider the following sequence: 5, 8, 4, 3, 8, 6, 2. The sequence is going to be sorted in ascending order, and bubble sort algorithm that compares two adjacent numbers from right to left is going to be used. How many swaps are performed during the algorithm? During the kk-th round of data procession, assuming there are nn elements, first we compare the (n−1)(n-1)-th and nn-th element and swap them if necessary, then (n−2)(n-2)-th and (n−1)(n-1)-th, etc., and at the end of the kk-th round we compare and swap the kk-th and the (k+1)(k+1)-th element.

Отговори

Решение


Оригинал в Архива: blitz.pdf · официални решения: blitz-answers.pdf