编程介的小学生 2017-08-06 09:24 采纳率: 20.5%
浏览 686
已采纳

Piano

Minami is a pianist. Both her left and right hands can touch at most 9 keys and should occupy at least 5 keys from the thumb to the little finger.

Now she wants to play a simple piano piece on a piano which has 52 white-keys and 36 black-keys. The piece is easy because she should only hit one key. If she can't touch one key, she should move her arm. Moving arm costs her f(x) energy. f(x) is a function about the distance of the thumb's moving, x: f(x) = floor(sqrt(x)).

Now you are given the keys where her left and right thumbs are, and the compose containing only numbers instead of notes. All numbers in the compose are from 0 to 51 indicating the 52 white-keys on the piano. The number 0 denotes the left most key. When playing the piano, The left hand can be on the right side. But, one finger touching the key between two fingers of the other hand is fobidden.

Output the minimal energy cost.

Input

There are no more than 20 cases. For each case, the first line contains 3 integers L, R, N (4 ≤ L ≤ 51, 0 ≤ R ≤ 47, 1 ≤ N ≤ 1000). L and R indicate the keys where her left and right thumbs are before playing. There are N lines followed. Each line contains one integer indicating the key Minami should play next.

Output

Output the minimal energy cost in a single line.

Sample Input

10 20 10
0
1
2
3
4
5
6
7
8
9
Sample Output

2

  • 写回答

2条回答 默认 最新

查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?