当前位置:网站首页>Codeforces Round #614 (Div. 2) A. ConneR and the A.R.C. Markland-N
Codeforces Round #614 (Div. 2) A. ConneR and the A.R.C. Markland-N
2022-07-28 10:15:00 【小柳学渣】
time limit per test: 1 second
memory limit per test: 256 megabytes
inputstandard input
outputstandard output
Sakuzyo - Imprinting
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!
Input
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≤10^9, 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.
Output
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.
Example
input
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
output
2
0
4
0
2
Note
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.
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
int n,s,k;
cin>>n>>s>>k;
int min=0;
map<int,int>m;
while(k--)
{
int x;
cin>>x;
m[x]=1;
}
int i=0;
for(i=0;;i++)
{
if(s-i>0)
{
if(m.find(s-i)==m.end())break;
}
if(s+i<=n&&m.find(s+i)==m.end())break;
}
cout<<i<<endl;
}
return 0;
}
边栏推荐
- 按位与、或、异或等运算方法
- 华为入股石墨烯材料厂商富烯科技,持股10%
- What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?
- Idea packages jar packages and runs jar package commands
- 10. The penultimate node in the linked list
- 3.用数组逆序打印链表
- Ueeditor v1.4.3 control file compression
- 问题总结档案
- ogg参数filter的使用问题【急】
- Record a parent-child project in idea, modify the name of project and module, and test it personally!
猜你喜欢

数据库安全 --- 创建登录名 用户+配置权限【笔记】

C语言 二级指针详解及示例代码

gcc: error trying to exec 'as': execvp: No such file or directory

11. Linked list inversion

Get to know SuperMap idesktop for the first time

IDEA创建我的第一个项目

【微信小程序】项目实战—抽签应用

14. Double pointer - the container that holds the most water

SQL Server 2016 学习记录 --- 嵌套查询

7、二分法——寻找一组重复或者有序但是旋转的数组
随机推荐
12. Double pointer -- merge two ordered linked lists
用两个栈实现一个队列【C语言】
Add new startup logo and startup / shutdown animation in mt6735
数据库安全 --- 创建登录名 用户+配置权限【笔记】
Consul
Aqua Data Studio 18.5.0导出insert语句
14. Double pointer - the container that holds the most water
Idea packages jar packages and runs jar package commands
15、判断二维数组中是否存在目标值
6、双指针——递增数组两数之和与目标数相等
死锁算法:银行家算法和安全性算法
13、哈希表——两个链表第一个公共节点
SQL Server 2016 学习记录 --- 数据定义
15. Judge whether the target value exists in the two-dimensional array
IDEA创建我的第一个项目
Can kingbasees v8r6 JDBC use VIP?
JVM principle
SuperMap iserver publishing management and calling map services
读写分离备机备份报错
吴雄昂遭Arm罢免内幕:建私人投资公司,损害了股东利益?