304803: CF915B. Browser
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Browser
题意翻译
题目描述 Luba正在网上冲浪。她在浏览器里打开了n个标签,从左到右编号为1到n。目前鼠标光标的位置在第pos个标签。Luba需要使用编号从l到r(包含l与r)的标签,并且她想尽可能快地关闭其它的标签。 Luba每秒可以把光标往左移或者往右移(如果光标当前在标签ii,则她可以将光标移到标签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 为了只留下初始编号从ll到rr的标签,Luba至少花费多少秒钟? 输入格式 输入只有一行,包括四个整数n,pos,l,r(1<=n<=100 , 1<=pos<=n ,1<=l<=r<=n)——标签的数量,光标的位置与Luba需要留下的标签的范围。 输出格式 输出一个整数,表示关闭除了范围[l,r]以外的所有标签所需的最短秒数。 样例说明 第一个样例中Luba需要做下面的操作:移动光标至标签2,关闭它左边的所有标签,移动光标到标签3,再到标签4,然后关闭它右边的所有标签。 第二个样例中她只需要关闭光标右边的所有标签。 第三个样例中Luba不需要做任何事。题目描述
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?输入输出格式
输入格式
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.
输出格式
Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment $ [l,r] $ .
输入输出样例
输入样例 #1
6 3 2 4
输出样例 #1
5
输入样例 #2
6 3 1 3
输出样例 #2
1
输入样例 #3
5 2 1 5
输出样例 #3
0