The Final Level
Time limit3sMemory limit512 MB
Find the minimum number of L-shaped n-blocks needed to cover a connected path of squares from (0,0) to (a,b) on an infinite grid.
- Level
Hard8 of 10
- Topics
- Math, Greedy, Implementation, Geometry
- Solved
- No attempts yet
Problem
Fiora designs games. She is now laying out the final level of a new game.
A level is a labyrinth on a square grid. The player starts on the square and has to reach the square .
Fiora works in a level editor that offers a single building block: an L-shaped corner made of two perpendicular rectangles that share one square, so one block covers squares. A block can be rotated in four ways. Blocks must not overlap, but they may touch. The player walks on any square covered by a block and moves between two squares that share a side, even when the two squares belong to different blocks. Every square on the player's route is covered by a block, so the start square and the goal square are covered as well.

Blocks with .
Fiora wants the level to use as few blocks as possible while the player can still get from to . Find that minimum for each test case.
Input
The first line has one integer (), the number of test cases. Each of the next lines has three integers , , (; ). Here is the horizontal coordinate of the goal square, is its vertical coordinate, and is the length of each rectangle of a block. The goal square is not the start square, so or .
Output
For each test case, print the minimal number of blocks on its own line. Print only this number, not the arrangement of the blocks.