people sit in a row. Couples are numbered . Find the minimum swaps to seat every couple together. For , one swap gives . Answer is .
Here's a cycle-counting problem disguised as greedy.
Think about the relationship between people and positions.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Minimum swaps
people sit in a row. Couples are numbered . Find the minimum swaps to seat every couple together. For , one swap gives . Answer is .
Here's a cycle-counting problem disguised as greedy.
Think about the relationship between people and positions.