309915: CF1759C. Thermostat

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Thermostat

题意翻译

共 $t$ 组输入。 对于每组输入,有五个整数 $l,r,x,a,b$。 对于一个 $p$ 的操作,可以从 $p$ 变成 $q$,但是要保证 $|p-q|\ge x$ 且 $l\le q\le r$。 问从 $a$ 到 $b$ 需要的最少操作数,若不能到 $b$ 输出 `-1`(题目保证 $l\le a,b \le r$)。 Translated by @_JYqwq_

题目描述

Vlad came home and found out that someone had reconfigured the old thermostat to the temperature of $ a $ . The thermostat can only be set to a temperature from $ l $ to $ r $ inclusive, the temperature cannot change by less than $ x $ . Formally, in one operation you can reconfigure the thermostat from temperature $ a $ to temperature $ b $ if $ |a - b| \ge x $ and $ l \le b \le r $ . You are given $ l $ , $ r $ , $ x $ , $ a $ and $ b $ . Find the minimum number of operations required to get temperature $ b $ from temperature $ a $ , or say that it is impossible.

输入输出格式

输入格式


The first line of input data contains the single integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each case contains three integers $ l $ , $ r $ and $ x $ ( $ -10^9 \le l \le r \le 10^9 $ , $ 1 \le x \le 10^9 $ ) — range of temperature and minimum temperature change. The second line of each case contains two integers $ a $ and $ b $ ( $ l \le a, b \le r $ ) — the initial and final temperatures.

输出格式


Output $ t $ numbers, each of which is the answer to the corresponding test case. If it is impossible to achieve the temperature $ b $ , output -1, otherwise output the minimum number of operations.

输入输出样例

输入样例 #1

10
3 5 6
3 3
0 15 5
4 5
0 10 5
3 7
3 5 6
3 4
-10 10 11
-5 6
-3 3 4
1 0
-5 10 8
9 2
1 5 1
2 5
-1 4 3
0 2
-6 3 6
-1 -4

输出样例 #1

0
2
3
-1
1
-1
3
1
3
-1

说明

In the first example, the thermostat is already set up correctly. In the second example, you can achieve the desired temperature as follows: $ 4 \rightarrow 10 \rightarrow 5 $ . In the third example, you can achieve the desired temperature as follows: $ 3 \rightarrow 8 \rightarrow 2 \rightarrow 7 $ . In the fourth test, it is impossible to make any operation.

Input

题意翻译

共 $t$ 组输入。 对于每组输入,有五个整数 $l,r,x,a,b$。 对于一个 $p$ 的操作,可以从 $p$ 变成 $q$,但是要保证 $|p-q|\ge x$ 且 $l\le q\le r$。 问从 $a$ 到 $b$ 需要的最少操作数,若不能到 $b$ 输出 `-1`(题目保证 $l\le a,b \le r$)。 Translated by @_JYqwq_

Output

**题意翻译**

共 $ t $ 组输入。

对于每组输入,有五个整数 $ l,r,x,a,b $。

对于一个 $ p $ 的操作,可以从 $ p $ 变成 $ q $,但是要保证 $ |p-q|\ge x $ 且 $ l\le q\le r $。

问从 $ a $ 到 $ b $ 需要的最少操作数,若不能到 $ b $ 输出 `-1`(题目保证 $ l\le a,b \le r $)。

**题目描述**

Vlad回家发现有人把旧恒温器的温度调到了 $ a $。

恒温器只能设置从 $ l $ 到 $ r $(包括 $ l $ 和 $ r $)的温度,温度变化不能小于 $ x $。正式地,一次操作可以将恒温器从温度 $ a $ 调整到温度 $ b $,如果 $ |a - b| \ge x $ 且 $ l \le b \le r $。

给你 $ l $, $ r $, $ x $, $ a $ 和 $ b $。找出从温度 $ a $ 获得温度 $ b $ 所需的最少操作数,或者判断这是不可能的。

**输入输出格式**

**输入格式**

输入数据的第一行包含单个整数 $ t $ ($ 1 \le t \le 10^4 $) — 测试用例的数量。

接下来是每个测试用例的描述。

每个测试用例的第一行包含三个整数 $ l $, $ r $ 和 $ x $ ($ -10^9 \le l \le r \le 10^9 $, $ 1 \le x \le 10^9 $) — 温度范围和最小温度变化。

每个测试用例的第二行包含两个整数 $ a $ 和 $ b $ ($ l \le a, b \le r $) — 初始温度和最终温度。

**输出格式**

输出 $ t $ 个数,每个数是对应测试用例的答案。如果不能达到温度 $ b $,输出 -1,否则输出所需的最少操作数。

**输入输出样例**

**输入样例 #1**

```
10
3 5 6
3 3
0 15 5
4 5
0 10 5
3 7
3 5 6
3 4
-10 10 11
-5 6
-3 3 4
1 0
-5 10 8
9 2
1 5 1
2 5
-1 4 3
0 2
-6 3 6
-1 -4
```

**输出样例 #1**

```
0
2
3
-1
1
-1
3
1
3
-1
```

**说明**

在第一个例子中,恒温器已经设置正确。

在第二个例子中,可以通过以下方式达到期望的温度:$ 4 \rightarrow 10 \rightarrow 5 $。

在第三个例子中,可以通过以下方式达到期望的温度:$ 3 \rightarrow 8 \rightarrow 2 \rightarrow 7 $。

在第四个测试中,不可能进行任何操作。**题意翻译** 共 $ t $ 组输入。 对于每组输入,有五个整数 $ l,r,x,a,b $。 对于一个 $ p $ 的操作,可以从 $ p $ 变成 $ q $,但是要保证 $ |p-q|\ge x $ 且 $ l\le q\le r $。 问从 $ a $ 到 $ b $ 需要的最少操作数,若不能到 $ b $ 输出 `-1`(题目保证 $ l\le a,b \le r $)。 **题目描述** Vlad回家发现有人把旧恒温器的温度调到了 $ a $。 恒温器只能设置从 $ l $ 到 $ r $(包括 $ l $ 和 $ r $)的温度,温度变化不能小于 $ x $。正式地,一次操作可以将恒温器从温度 $ a $ 调整到温度 $ b $,如果 $ |a - b| \ge x $ 且 $ l \le b \le r $。 给你 $ l $, $ r $, $ x $, $ a $ 和 $ b $。找出从温度 $ a $ 获得温度 $ b $ 所需的最少操作数,或者判断这是不可能的。 **输入输出格式** **输入格式** 输入数据的第一行包含单个整数 $ t $ ($ 1 \le t \le 10^4 $) — 测试用例的数量。 接下来是每个测试用例的描述。 每个测试用例的第一行包含三个整数 $ l $, $ r $ 和 $ x $ ($ -10^9 \le l \le r \le 10^9 $, $ 1 \le x \le 10^9 $) — 温度范围和最小温度变化。 每个测试用例的第二行包含两个整数 $ a $ 和 $ b $ ($ l \le a, b \le r $) — 初始温度和最终温度。 **输出格式** 输出 $ t $ 个数,每个数是对应测试用例的答案。如果不能达到温度 $ b $,输出 -1,否则输出所需的最少操作数。 **输入输出样例** **输入样例 #1** ``` 10 3 5 6 3 3 0 15 5 4 5 0 10 5 3 7 3 5 6 3 4 -10 10 11 -5 6 -3 3 4 1 0 -5 10 8 9 2 1 5 1 2 5 -1 4 3 0 2 -6 3 6 -1 -4 ``` **输出样例 #1** ``` 0 2 3 -1 1 -1 3 1 3 -1 ``` **说明** 在第一个例子中,恒温器已经设置正确。 在第二个例子中,可以通过以下方式达到期望的温度:$ 4 \rightarrow 10 \rightarrow 5 $。 在第三个例子中,可以通过以下方式达到期望的温度:$ 3 \rightarrow 8 \rightarrow 2 \rightarrow 7 $。 在第四个测试中,不可能进行任何操作。

加入题单

算法标签: