1035. Comfort

单点时限: 2.0 sec

内存限制: 256 MB

A game-board consists of N fields placed around a circle. Fields are successively numbered from1 to N clockwise. In some fields there may be obstacles.

Player starts on a field marked with number 1. His goal is to reach a given field marked with number Z. The only way of moving is a clockwise jump of length K. The only restriction is that the fields the player may jump to should not contain any obstacle.

For example, if N = 13, K = 3 and Z = 9, the player can jump across the fields 1, 4, 7, 10, 13, 3, 6 and 9, reaching his goal under condition that none of these fields is occupied by an obstacle.

Your task is to write a program that finds the smallest possible number K.

输入格式

It contains multi-testcases.(**** Please notice that it has more than one test case and please use While(scanf()!=EOF) just as problem 1000)

First line of the each testcase consists of integers N, Z and M, 2 <= N <= 1000, 2 <= Z <= N, 0 <= M <= N - 2. N represents number of fields on the game-board and Z is a given goal-field.

Next line consists of M different integers that represent marks of fields having an obstacle. It is confirmed that fields marked 1 and Z do not contain an obstacle.

输出格式

For each testcase output a line contains the requested number K described above.

样例

Input
9 7 2
2 3
9 7 2
2 3
Output
3
3

29 人解决,55 人已尝试。

36 份提交通过,共有 213 份提交。

5.7 EMB 奖励。

创建: 18 年,5 月前.

修改: 6 年,9 月前.

最后提交: 2 年,7 月前.

来源: N/A

题目标签