当前位置 : 主页 > 编程语言 > java >

CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】

来源:互联网 收集:自由互联 发布时间:2022-07-13
​​题目传送门​​ 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”


​​题目传送门​​


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 CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_#include

The first line of a test case contains three integers CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_#define_02, CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_sed_03 and CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_#define_049CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_#include_05

The second line of a test case contains k distinct integers CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_#define_06

It is guaranteed that the sum of CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_#define_07 over all test cases does not exceed CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_#define_08.


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.


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.


题意

  • 一栋楼有CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_#define_09个楼层,每层一个饭店,你在第CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_#include_10层,有CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_#define_11家关门的饭店,求去最近的开门的饭店的最少层数。

题解

  • 暴力即可,注意数据范围,CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_#include_129,不能直接开数组CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_#include_13查找
  • 记得开CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_sed_14CodeForces 1293A——ConneR and the A.R.C. Markland-N【签到题】_sed_14

AC-Code

#include <bits/stdc++.h>
using namespace std;
#define

ll a[maxn];
ll num;
int main() {
int T;
cin >> T;
while (T--) {
num = 0;
ll n, s, k;
cin >> n >> s >> k;
for (ll i = 0; i < k; ++i) {
cin >> a[num++];
}
sort(a, a + num);
bool f = true;
ll x = -0x7fffffff7fffffff, y = 0x7fffffff7fffffff;
for (ll i = s; i >= s - k && i > 0 && f; --i) {
ll* xi = lower_bound(a, a + num, i);
if (xi == a + num || (*xi != i)) {
x = i;
f = false;
}
}
f = true;
for (ll i = s + 1; i <= s + k && i <= n && f; ++i) {
ll* xi = lower_bound(a, a + num, i);
if (xi == a + num || (*xi != i)) {
y = i;
f = false;
}
}
ll ans = min(s - x, y - s);
cout << ans << endl;
}
return 0;
}


上一篇:面试官:解释一下ThreadLocal 核心原理
下一篇:没有了
网友评论