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

Автор adsijf, история, 3 года назад, По-английски

UVa 1315

Someone help me solve this problem please, I don't know how to find formula for this problem

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

»
3 года назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

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)$$$.