#P4368. [Code+#4] 喵呜
[Code+#4] 喵呜
Description
There is a neat row of cherry trees along the roadside, each exactly of height . One day, a cute kitten happened to climb onto the trees to play, but she is a bit allergic to cherry blossoms, so she now wants to leave these cherry trees as soon as possible.
Specifically, the kitten is currently at height on the -th cherry tree. She can leave the cherry trees by using two types of jumps:
Light jump: Move trees to the left or right while decreasing the height by . That is, in one light jump, she can move from the starting point to height on the -th or -th tree. Note that when the kitten’s current height is not greater than , a light jump cannot be used.
Strong jump: Move trees to the left or right while increasing the height by . That is, in one strong jump, she can move from the starting point to height on the -th or -th tree. Note that when the kitten’s current height is greater than , a strong jump cannot be used.
To leave this stretch of cherry trees, the kitten needs to move to either the -st or the -th tree, at height or (so that she can breathe fresh air or just walk away from the trees). Now she wants to know the minimum number of jumps required to achieve the goal. Since she is a cute kitten, she hopes you will tell her.
Input Format
Read from standard input.
The first line contains a positive integer , the number of groups of testdata. There are no blank lines between groups.
Then follow lines, each describing one group of data:
Each group consists of one line containing six positive integers , whose meanings are as described in the problem statement.
Output Format
Output to standard output.
The output consists of groups of results, with no blank lines between groups. For each group of data:
If the kitten can successfully leave the cherry trees, output the minimum number of jumps she needs.
If the kitten cannot leave the cherry trees using the given jump methods, please output -1.
3
5 5 3 3 2 2
5 7 3 5 2 2
5 7 4 6 1 1
1
1
1
3
5 5 3 3 3 2
5 7 1 4 2 2
5 7 1 2 1 2
-1
-1
-1
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
454545454544
343434343433
-1
-1
Hint
| Test point ID | Range of | Special note |
|---|---|---|
| None | ||
| None | ||
| None | ||
| None |
For all testdata, it is guaranteed that , , .
Credit: https://www.luogu.org/discuss/show/38908
Translated by ChatGPT 5
京公网安备 11011102002149号