Huawei OD computer test - reflection counting (Java & JS & Python & C)

Question description

Given a two-dimensional matrix containing 0s and 1s.

Given an initial position and speed, an object starts from the given initial position, moves at a given speed, and specular emission occurs when it encounters the edge of the matrix.

Whether the object passes through 0 or 1, it does not affect its speed.

Please calculate and give the number of times the object passes through 1 point after t time unit.

The upper left corner of the matrix is ​​[0, 0] (column (x), row (y)). For example, the coordinates of point A below are [2, 1] (second column, first row)

Notice:

  1. If the initial position point is 1, it is also counted
  2. The minimum unit of time is 1, and points that pass within less than 1 time unit are not considered.

Enter description

The first line is initial information

<w><h><x><y><sx><sy><t>

Starting from the second row, there are h rows in total, which are two-dimensional matrix information.

in:

  • w, h are the width and height of the matrix
  • x, y are the starting position
  • sx, sy are the initial speed
  • t is the elapsed time

All inputs are valid and the data range is as follows:

  • 0 < w < 100

Supongo que te gusta

Origin blog.csdn.net/qfc_128220/article/details/135279570
Recomendado
Clasificación