编程介的小学生 2017-09-14 08:17 采纳率: 20.5%
浏览 710
已采纳

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

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services