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

网友投稿 727 2022-11-02

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

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

​​题目传送门​​

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

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.

题意

题解

AC-Code

#include using namespace std;#definell 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;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:struts2造成的多次提交和ajax调用不进入后台问题发现和解决
下一篇:wechat-proxy:用于全局缓存微信 access_token 和转发微信回调消息的服务器程序
相关文章

 发表评论

暂时没有评论,来抢沙发吧~