编程介的小学生 2017-09-06 04:19 采纳率: 20.5%
浏览 795
已采纳

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条回答

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大