CF1082A Vasya and Book
题目描述
Vasya有一本 $n$ 页的电子书,她每次可以向前或向后翻 $d$ 页(但她不能翻到书外面去)。现在她要从第 $x$ 页翻到第 $y$ 页,求她最少翻的次数。
输入格式
输入第一行一个整数 $t$ $(1\le t\le 10^3)$ 表示数据组数。
接下来 $t$ 行,每行 $4$ 个正整数 $n,x,y,d$ .$(1\le n,d \le 10^9,1\le x,y\le n)$.
输出格式
输出一个整数表示最少翻页次数,如果翻不到则输出 $-1$.
说明/提示
In the first test case the optimal sequence is: $ 4 \rightarrow 2 \rightarrow 1 \rightarrow 3 \rightarrow 5 $ .
In the second test case it is possible to get to pages $ 1 $ and $ 5 $ .
In the third test case the optimal sequence is: $ 4 \rightarrow 7 \rightarrow 10 \rightarrow 13 \rightarrow 16 \rightarrow 19 $ .