1269: 爱看电视的LsF
时间限制: 1 秒 内存限制: 64 MB
提交: 312 解决: 77
提交 状态
题目描述
LsF(刘师傅)非常喜欢看电视!
不幸的是,遥控器上的一些数字按钮坏了。 但他灵光一闪,如果他不能直接输入他想要看到的频道的号码,那么他可以先输入其他号码,再通过按下按钮+ 和- (这两个按钮由24K钛合金制成,永远不会坏)的方式到达所需的频道。 按钮+将数字增加1,按钮-将数字减少1。当然他依然可以使用那些完好无损的数字按钮输入号码。
他最初在第S频道,他想看第T频道。他想知道由S到T频道所需的最少按钮按压次数。
输入
输入包含多组数据。
对于每组数据,第一行是三个整数n,S,T(n≤10,0≤S,T≤500,000。 第二行是n个数字 a1,a2,…,an,表示数字 ai键已经坏了 (0≤ai≤9,ai≠aj when i≠j)。
输出
输入包含多组数据。
对于每组数据,第一行是三个整数n,S,T(n≤10,0≤S,T≤500,000。 第二行是n个数字 a1,a2,…,an,表示数字 ai键已经坏了 (0≤ai≤9,ai≠aj when i≠j)。
样例输入
10 1 100
0 1 2 3 4 5 6 7 8 9
9 1 100
0 1 2 3 4 5 6 7 8
样例输出
99
3
思路:
由于频道最多50w,遍历所有频道,判断是否能够通过键盘直达这个频道,然后计算这个频道与目标频道的差值(一直按加频道或者减频道),最后取最小。