Someone help me solve this problem please, I don't know how to find formula for this problem
# | User | Rating |
---|---|---|
1 | ecnerwala | 3649 |
2 | Benq | 3581 |
3 | jiangly | 3578 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | tourist | 3565 |
8 | maroonrk | 3531 |
9 | Radewoosh | 3521 |
10 | Um_nik | 3482 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 161 |
4 | TheScrasse | 159 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | SecondThread | 146 |
8 | orz | 146 |
10 | pajenegod | 145 |
Name |
---|
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)$$$.