101354: [AtCoder]ABC135 E - Golf

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $500$ points

Problem Statement

Jumbo Takahashi will play golf on an infinite two-dimensional grid.

The ball is initially at the origin $(0, 0)$, and the goal is a grid point (a point with integer coordinates) $(X, Y)$. In one stroke, Jumbo Takahashi can perform the following operation:

  • Choose a grid point whose Manhattan distance from the current position of the ball is $K$, and send the ball to that point.

The game is finished when the ball reaches the goal, and the score will be the number of strokes so far. Jumbo Takahashi wants to finish the game with the lowest score possible.

Determine if the game can be finished. If the answer is yes, find one way to bring the ball to the goal with the lowest score possible.

What is Manhattan distance?

The Manhattan distance between two points $(x_1, y_1)$ and $(x_2, y_2)$ is defined as $|x_1-x_2|+|y_1-y_2|$.

Constraints

  • All values in input are integers.
  • $1 \leq K \leq 10^9$
  • $-10^5 \leq X, Y \leq 10^5$
  • $(X, Y) \neq (0, 0)$

Input

Input is given from Standard Input in the following format:

$K$
$X$ $Y$

Output

If the game cannot be finished, print -1.

If the game can be finished, print one way to bring the ball to the destination with the lowest score possible, in the following format:

$s$
$x_1$ $y_1$
$x_2$ $y_2$
$.$
$.$
$.$
$x_s$ $y_s$

Here, $s$ is the lowest score possible, and $(x_i, y_i)$ is the position of the ball just after the $i$-th stroke.


Sample Input 1

11
-1 2

Sample Output 1

3
7 4
2 10
-1 2
  • The Manhattan distance between $(0, 0)$ and $(7, 4)$ is $|0-7|+|0-4|=11$.
  • The Manhattan distance between $(7, 4)$ and $(2, 10)$ is $|7-2|+|4-10|=11$.
  • The Manhattan distance between $(2, 10)$ and $(-1, 2)$ is $|2-(-1)|+|10-2|=11$.

Thus, this play is valid.

Also, there is no way to finish the game with less than three strokes.


Sample Input 2

4600
52 149

Sample Output 2

-1

Sample Input 3

4
9 9

Sample Output 3

5
1 3
4 2
4 6
6 8
9 9

Input

题意翻译

高桥将在无限的二维网格上打高尔夫球。 球最初位于原点(0,0)(0,0),目标是一个网格点(一个具有整数坐标的点)(X,Y)(X,Y)。在一次笔划中,高桥可以执行以下操作: 选择一个网格点,其曼哈顿距离球的当前位置为K,然后将球发送到该点。 当球到达球门时,比赛结束,比分将是目前为止的击球次数。高桥希望以尽可能低的比分结束比赛。 确定游戏是否可以结束。如果答案是肯定的,找一种方法把球带到可能得分最低的球门。 曼哈顿距离是:两个点($x$1,$y$1)和($x$2,$y$2)之间的曼哈顿距离定义为| $x$1-$x$2 |+| $y$1-$y$2 | 按顺序输入:$k$ $x$ $ y$ 输出格式: 如果游戏无法完成,请打印-1。 如果游戏可以完成,请按以下格式打印一种将球带到可能得分最低的目的地的方法: $ s $ $ x_1 $ $ y_1 $ $ x_2 $ $ y_2 $ $ . $ $ . $ $ . $ $ x_s $ $ y_s $ 这里s是可能的最低分,而($xi$,$yi$)是第二次击球后球的位置。

加入题单

算法标签: