#GL0000322. Số bước bóng nảy (Bouncing Ball Steps)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số bước bóng nảy (Bouncing Ball Steps)
Bouncing Ball Steps
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an grid indexed from . A ball starts in the top-left cell and initially moves diagonally down and right. Every step moves it by one row and one column in its current direction. On reaching a top/bottom border the vertical component reverses, and on reaching a left/right border the horizontal component reverses. At a corner both components may reverse simultaneously.
After exactly steps, determine the ball's position and the number of times it has changed direction. Simultaneous reversals at a corner count as one direction change. A collision occurring at the end of step is included.
Input
One line contains : the number of rows, the number of columns, and the number of steps.
Output
Print three space-separated integers : the row and column after steps, and the number of direction changes.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Example 1
Input
3 4 0
Output
1 1 0
Explanation
No steps have been taken; the ball remains at with no direction changes.
Example 2
Input
3 4 3
Output
2 4 2
Explanation
Step 1 reaches . Step 2 reaches and reverses vertically (first change). Step 3 reaches and reverses horizontally (second change).