ZOJ Problem Set - 2031
Given a list of songs, calculate the minimal number of keys a user has to press to move the cursor from a certain song to another.
There are 3 keys with different functions: "previous", "next" and "sort". When the "previous" key is pressed, the cursor moves to the previous song, if it's already at the first song, it goes to the last one. The "next" key works analogously. When the "sort" key is pressed, the list is sorted alphabetically. Each song has it's title and author, if the "sort" key is pressed when the list is sorted by title, it sorts the list by author, and vice versa. After sorting, the cursor stays at the same song.
6 1 4
Author: PAN, Minghao
Source: ZOJ Monthly, November 2003