题目描述
Problem Description
Along the roadside, there is a row of neatly arranged $n$ cherry blossom trees, each with a height exactly $h$. One day, a cute little cat accidentally runs up to play on these trees, but she is allergic to cherry blossoms, so she wants to leave these trees as soon as possible.
Specifically, the cat is currently on the $x$-th tree at a height of $y$. She can leave the trees by making two types of jumps:
- Light Jump: Move left or right by $a$ trees while descending by $b$ in height. A light jump can move from the starting point to the $x+a$ or $x-a$-th tree at a height of $y-b$. Note that a light jump cannot be used when the cat's height is not greater than $b$.
- Forceful Jump: Move left or right by $a$ trees while ascending by $b$ in height. A forceful jump can move from the starting point to the $x+a$ or $x-a$-th tree at a height of $y+b$. Note that a forceful jump cannot be used when the cat's height is greater than $h-b$.
To leave the cherry blossom trees, the cat needs to move to the $1$st or $n$-th tree at a height of $h$ or $1$ (so she can breathe fresh air or simply walk away from the trees). Now, the cat wants to know the minimum number of jumps required to achieve this goal. Since she is a cute little cat, she hopes you can tell her.
Input Format
Input is read from the standard input.
The first line contains a positive integer $T$, indicating the number of test cases. There are no blank lines between test cases.
The next $T$ lines describe each test case:
Each line contains six positive integers $n, h, x, y, a, b$, as described in the problem statement.
Output Format
Output is written to the standard output.
The output consists of $T$ lines, with no blank lines between them. For each test case:
- If the cat can successfully leave the cherry blossom trees, output the minimum number of jumps required.
- If the cat cannot leave the trees using the given jumping methods, output -1.
Sample Input and Output
Sample Input #1
3
5 5 3 3 2 2
5 7 3 5 2 2
5 7 4 6 1 1
Sample Output #1
1
1
1
Sample Input #2
3
5 5 3 3 3 2
5 7 1 4 2 2
5 7 1 2 1 2
Sample Output #2
-1
-1
-1
Sample Input #3
4
999999999999 999999999999 454545454545 454545454545 1 1
777777777777 777777777777 343434343434 343434343434 1 1
777777777777 999999999999 343434343434 454545454545 1 1
999999999999 777777777777 454545454545 343434343434 1 1
Sample Output #3
454545454544
343434343433
-1
-1
Notes/Hints
| Test Case Number | Range of $n, h$ | Special Conditions |
|---|---|---|
| $1,2$ | $\le 10$ | $b = 1$ |
| $3,4$ | $\le 10$ | $a = b = 1$ |
| $5,6,7,8$ | $\le 10$ | None |
| $9,10$ | $\le 500$ | $b = 1$ |
| $11,12$ | $\le 500$ | $a = b = 1$ |
| $13,14,15$ | $\le 500$ | None |
| $16,17$ | $\le 10^5$ | $h \le 10$ |
| $18,19,20$ | $\le 10^5$ | None |
| $21,22$ | $\le 10^{15}$ | $h \le 10$ |
| $23,24,25$ | $\le 10^{15}$ | None |
For all data, it is guaranteed that $n \geq 2$, $a < n$, and $b \leq h$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分