CF1759C.Thermostat

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vlad came home and found out that someone had reconfigured the old thermostat to the temperature of aa.

The thermostat can only be set to a temperature from ll to rr inclusive, the temperature cannot change by less than xx. Formally, in one operation you can reconfigure the thermostat from temperature aa to temperature bb if ∣a−b∣≥x|a - b| \ge x and l≤b≤rl \le b \le r.

You are given ll, rr, xx, aa and bb. Find the minimum number of operations required to get temperature bb from temperature aa, or say that it is impossible.

弗拉德回到家,发现有人将旧恒温器的温度重新设置为了 aa。

该恒温器只能被设定在区间 [l,r][l, r] 内(含端点)的温度值,且每次调节的温度变化量不能小于 xx。形式化地说,在一次操作中,你可以将恒温器从当前温度 aa 重新设置为温度 bb,当且仅当满足 ∣a−b∣≥x|a - b| \ge x 且 l≤b≤rl \le b \le r。

现给你 ll、rr、xx、aa 和 bb。请找出从温度 aa 到达温度 bb 所需的最少操作次数;若无法实现,请说明这是不可能的。

输入格式

The first line of input data contains the single integer tt (1≤t≤1041 \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 ll, rr and xx (−109≤l≤r≤109-10^9 \le l \le r \le 10^9, 1≤x≤1091 \le x \le 10^9) — range of temperature and minimum temperature change.

The second line of each case contains two integers aa and bb (l≤a,b≤rl \le a, b \le r) — the initial and final temperatures.

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

随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 ll、rr 和 xx(−109≤l≤r≤109-10^9 \le l \le r \le 10^9,1≤x≤1091 \le x \le 10^9)——温度范围及最小温度变化量。

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

输出格式

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

输出 tt 个数字,每个数字对应一个测试用例的答案。如果无法达到温度 bb,则输出 −1-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

说明/提示

In the first example, the thermostat is already set up correctly.

In the second example, you can achieve the desired temperature as follows: 4→10→54 \rightarrow 10 \rightarrow 5.

In the third example, you can achieve the desired temperature as follows: 3→8→2→73 \rightarrow 8 \rightarrow 2 \rightarrow 7.

In the fourth test, it is impossible to make any operation.

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

在第二个例子中,你可以通过以下方式达到目标温度:4→10→54 \rightarrow 10 \rightarrow 5。

在第三个例子中,你可以通过以下方式达到目标温度:3→8→2→73 \rightarrow 8 \rightarrow 2 \rightarrow 7。

在第四个测试用例中,无法执行任何操作。

输入解题思路,AI测评打分。不知道怎么写?

首页