CF915B.Browser
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible.
Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab i, then she can move it to the tab max(i - 1, a) or to the tab min(i + 1, b)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab i, she can close all the tabs with indices from segment [a, i - 1] or from segment [i + 1, b]). In the aforementioned expressions a and b denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then a = 3, b = 6.
What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from l to r inclusive opened?
卢巴正在上网。她当前的浏览器中打开了 n 个标签页,从左到右依次编号为 1 到 n。鼠标光标当前位于第 pos 个标签页上。卢巴的学习需要使用编号在区间 [l,r](含端点)内的所有标签页,她希望尽快关闭所有不属于该区间的标签页。
每秒钟,卢巴可以执行以下任一操作:
- 尝试将光标向左或向右移动(若光标当前位于第 i 个标签页,则可将其移至第 max(i−1,a) 个或第 min(i+1,b) 个标签页);
- 或尝试关闭光标左侧或右侧的所有标签页(若光标当前位于第 i 个标签页,则可关闭编号属于区间 [a,i−1] 或 [i+1,b] 的所有标签页)。
在上述表达式中,a 和 b 分别表示当前所有未关闭标签页的最小与最大编号。例如,若最初有 7 个标签页,而编号为 1、2 和 7 的标签页已被关闭,则此时 a=3,b=6。
问:卢巴至少需要花费多少秒,才能使得最终仅剩下初始编号在区间 [l,r](含端点)内的标签页处于打开状态?
输入格式
The only line of input contains four integer numbers n, pos, l, r (1 ≤ n ≤ 100, 1 ≤ pos ≤ n, 1 ≤ l ≤ r ≤ n) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened.
输入仅有一行,包含四个整数 n、pos、l、r(1 ≤ n ≤ 100,1 ≤ pos ≤ n,1 ≤ l ≤ r ≤ n),分别表示标签页的数量、光标位置以及 Luba 需要保持打开的区间。
输出格式
Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l, r].
输出一个整数,表示关闭区间 [l, r] 外所有标签页所需的最少秒数。
输入输出样例
输入#1
6 3 2 4
输出#1
5
输入#2
6 3 1 3
输出#2
1
输入#3
5 2 1 5
输出#3
0
说明/提示
In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.
In the second test she only needs to close all the tabs to the right of the current position of the cursor.
In the third test Luba doesn't need to do anything.
在第一个测试用例中,Luba 可以执行以下操作:将鼠标光标移动到第 2 个标签页,关闭其左侧的所有标签页;再将鼠标光标移动到第 3 个标签页,接着移动到第 4 个标签页,然后关闭其右侧的所有标签页。
在第二个测试用例中,她只需关闭鼠标光标当前位置右侧的所有标签页即可。
在第三个测试用例中,Luba 无需执行任何操作。
输入解题思路,AI测评打分。不知道怎么写?