编程介的小学生 2017-08-19 01:05 采纳率: 20.5%
浏览 755
已采纳

88's function

88 is the nickname of freecity, the most famous bbs in ZJU. It has so many user, and the number of articles in all boards are getting more and more every minute. It was hard to find an article even when you knew its index. But now, 88 has a new function, with which you can goto the article you want immediately after inputing its index. For example , when you want to goto the article at with index 75 , you can simply press the key '7' and '5' and at last the 'Enter' key, then you'll see you cursor before the 75th article. You can also use 'up' and 'down' key to go up or down one article respectively. If you want to goto '76', you can press '7' ,'5', 'Enter','down' four keys sequentially. (Though it is not a good way to goto '76', here it is just for explaining the function) 68 M swinge Jul 28 . missing you tonight.

69 M CoolBug Jul 29 Re: ec last night
70 M supercooker Jul 30 . Love in ec
71 M supercooker Jul 31 . Dancing on SuDi
72 M supercooker Jul 31 . Falling in love at first sight in EC
73 M freshboy Aug 1 . My experience of last night ec.
74 M zzx Aug 1 . A probable suicide of a PPMM
75 M supercooker Aug 2 . 88 to 88,ec,eb,and you all!
76 M freshboy Aug 2 . The ec of last night in my eyes!
77 M freshboy Aug 2 . The morning ec!
78 M nisson Aug 3 . A sight in last night's get-together
79 M freshboy Aug 4 . Crazy For English
80 M freshboy Aug 4 . My First Klatch With Friends Of English Board
81 M guyun Aug 4 . ec of park six this morning!
Topiori likes surfing on 88, and spends so much time on it that it is a great part of his daily life. But his keyboard has met some problems recently - some number keys do not work, while he still want to use it to surfing on 88. Now he is asking you for help: he wants to use the keyboard as least as possible to go to the correct article he's interesting in. He believe a good programmer like you can easily find the best way.
In this problem you can only use the number keys '0'-'9'(with some exceptions of bad keys specified in the input) and the 'Enter', 'up','down' keys, and every key can be used many times.

*Be a little difference from the real 88 operate, can't press 'down' key to go from the last article to the first one, also can't press 'up' key to go from the first one to the last.

Input

There are multiple test cases.
The first line of each case is an integer N (0 <= N <= 10), the number of bad keys. The next line are N integers, the bad number keys. The last line are two indices T and M. T is the beginning position of the cursor, and M is the index of the article wanted by topiori (0 < T,M <= 1,000,000).
In the example above, the best way is to press number key '7' and '5', then press the 'Enter' key.
And the total number of article is changing every second, so in this problem, you can consider the total number is large enough.

Output

With every case you just needed to output one line with one integer K, the least times of key pressing.

Sample Input

1
5
69 75

Sample Output

4
(Hint: '7', '4', 'Enter', 'down', or '7', '6', 'Enter', 'up')

  • 写回答

1条回答 默认 最新

  • devmiao 2017-08-29 16:40
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献