CF1293A.ConneR and the A.R.C. Markland-N
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
A.R.C. Markland-N 是一栋有 n 层楼的高楼,楼层编号从 1 到 n。大楼中每两个相邻楼层之间都有一段楼梯相连。
现在是我们的老师 Colin “ConneR” Neumann Jr. 的午餐时间,他正计划寻找一个合适的地方享用午餐。
ConneR 的办公室位于大楼的第 s 层。每一层楼(当然也包括第 s 层)都设有一家提供餐食的餐厅。然而,由于当前正在进行装修,其中有 k 家餐厅暂时停业,因此 ConneR 无法在这些餐厅用餐。
ConneR 希望尽快抵达一家仍在营业的餐厅,以节省时间。请问:他需要攀爬(或下降)的最少楼梯段数是多少,才能到达离他当前位置最近的一家目前营业中的餐厅?
请尽快回答他——你或许将赢得他的赞许,甚至有幸以优雅的 Neumann 风格与他共进午餐!
输入格式
The first line contains one integer t (1≤t≤1000) — the number of test cases in the test. Then the descriptions of t test cases follow.
The first line of a test case contains three integers n, s and k (2≤n≤109, 1≤s≤n, 1≤k≤min(n−1,1000)) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains k distinct integers a1,a2,…,ak (1≤ai≤n) — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of k over all test cases does not exceed 1000.
第一行包含一个整数 t(1≤t≤1000)—— 表示测试用例的数量。随后是 t 个测试用例的描述。
每个测试用例的第一行包含三个整数 n、s 和 k(2≤n≤109,1≤s≤n,1≤k≤min(n−1,1000))—— 分别表示 A.R.C. Markland-N 大楼的楼层数、ConneR 所在的楼层号,以及当前关闭的餐厅数量。
每个测试用例的第二行包含 k 个互不相同的整数 a1,a2,…,ak(1≤ai≤n)—— 表示当前关闭的餐厅所在的楼层号。
保证所有测试用例中 k 的总和不超过 1000。
输出格式
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.
对于每个测试用例,输出一个整数——ConneR 从第 s 层走到一家营业中的餐厅所在楼层所需的最少楼梯数量。
输入输出样例
输入#1
5 5 2 3 1 2 3 4 3 3 4 1 2 10 2 6 1 2 3 4 5 7 2 1 1 2 100 76 8 76 75 36 67 41 74 10 77
输出#1
2 0 4 0 2
说明/提示
In the first example test case, the nearest floor with an open restaurant would be the floor 4.
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the 6-th floor.
在第一个样例测试用例中,最近的拥有营业餐厅的楼层是第 4 层。
在第二个样例测试用例中,ConneR 办公室所在的楼层仍有一家营业的餐厅,因此 Sensei 无需前往其他楼层。
在第三个样例测试用例中,最近的营业餐厅位于第 6 层。
输入解题思路,AI测评打分。不知道怎么写?