Someone help me solve this problem please, I don't know how to find formula for this problem
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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)$$$.