Moving Object Recognition
Time limit1sMemory limit128 MB
Find the largest connected white blob in each image, track its centroid over time, and report the average per-second velocity in x and y, each to two decimals.
- Level
Medium7 of 10
- Topics
- BFS, Simulation, Implementation, Geometry
- Solved
- No attempts yet
Problem
There are many situations in which we need to know how fast an object is moving. For example, an air-traffic controller at an airport wants to know the speed of a descending plane and warn if it is too fast or too slow, speed cameras help the police catch speeding drivers, and so on.
In this problem you must write a program that recognizes the speed of a moving object.
Assume an object moves on a two-dimensional plane with a constant speed and direction. A camera takes one shot every second. Assume the camera records the true scene of the plane (you do not need to worry about the viewing angle).
The background is black and the only object is white, except for some noise introduced by the camera. You may assume that the largest continuous white area is always the object, and there is always exactly one such largest area.
Given several pictures taken by the camera, compute and output the speed of the object.
A picture is a matrix containing only . or x, where . is a black block and x is a white block. There are always at least two pictures.
Definitions
The speed of the object is the moving speed of the object's geometric center, defined as
Every object is made of unit square blocks, and the geometric center of a single block is the block's own center, so the geometric center of the object can be computed as
where is the coordinate of the center of the -th block and is the number of blocks in the object.
The average speed is computed as in a physics textbook:
where ranges over the discrete observation times from to . Here is half of the number of observation points (the number of observation points is always even), and is the observed position of the object's center at time , that is, the geometric center computed from the -th image.
Other definitions:
- Each block is a square (every
.orxis one such block). - A white area is a set of white blocks.
- A white area is a continuous white area if and only if any two of its blocks are joined by a path that stays inside the area and whose consecutive blocks share a common edge (4-directional adjacency).
- The positive direction is from left to right; the positive direction is from top to bottom.
- The largest continuous white area is always the object, and it is always unique.
- The object may appear with a different shape in different pictures.
Input
The input contains several data cases. Each case begins with a line containing two integers and . It is followed by several matrices ( columns, rows); each matrix is one picture taken by the camera, and there are always at least two pictures.
Within one case, consecutive matrices are separated by a line of - characters. The last matrix of a case is followed by a line of = characters.
A line containing two zeros marks the end of the input.
Each picture is at most , and one case contains at most pictures.
Output
For each test case, output one line with two numbers: the speed of the object in the and directions respectively, each printed to exactly two digits after the decimal point. Speeds are in mm/s.