编程介的小学生 2017-09-07 09:12 采纳率: 20.5%
浏览 804
已采纳

Song List

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.

Input

The input contains several cases. Each case begins with three positive integers: n, the number of songs(at most 10000), s and f, the initial and final position of the cursor(1 <= s, f <= n). Then n lines follow, each contains two strings with no more than 10 characters each, which are the title and the author of that song. The titles and authors are unique. Songs are initially sorted by title.

Output

For each case,output the minimal number of keys one has to press to move the cursor from its initial position to the final position.

Sample Input

6 1 4
a a
b c
c d
d b
e e
f f

Sample Output

2

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!