Someone help me solve this problem please, I don't know how to find formula for this problem
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Название |
---|
Let $$$n = 2q + r$$$, where $$$q = \lfloor \frac{n}{2} \rfloor$$$, and $$$r = n\mod2$$$. The minimum number of times two neighbors swap their positions such that all $$$n$$$ participants sit around the table in reverse order is related to the number of adjacent pair swap operations required to reverse an array. Reversing an array of size $$$k$$$ can be done in $$$k-1$$$ iterations, and requires $$$k-1, k-2, \ldots, 1$$$ swap operations, respectively. The total number of swap operations is then equal to $$$k \choose 2$$$. The answer should be to partition the participants into two equal or almost equal sized arrays: the first includes participants $$$1, 2, \ldots, q$$$, and the second includes participants $$$q+1, q+2, \ldots, 2q+r$$$. The total number of swap operations is then equal to $$$q \choose 2$$$+ $$$q+r \choose 2$$$ = $$$q(q+r-1)$$$.
Note that reversing the $$$n$$$ participants without partitioning requires $$$n \choose 2$$$ = $$$q(2q+2r-1)$$$ which is larger than the minimum value. In general, partitioning into $$$k$$$ and $$$n-k$$$ arrays and reversing each array independently requires $$$k \choose 2$$$+ $$$n-k \choose 2$$$ = $$$n \choose 2$$$ — $$$k(n-k)$$$ swap operations. It is simple to prove that the minimum value is achieved when $$$k = q$$$ and $$$k(n-k) = q(q+r)$$$.