CodeForces 549D (暴力、模拟)

The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computesHaar features. As part of this task, we consider a simplified model of this concept.

Let’s consider a rectangular image that is represented with a table of size n×m. The table elements are integers that specify the brightness of each pixel in the image.

A feature also is a rectangular table of sizen×m. Each cell of a feature is painted black or white.

To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value ofW-B, where W is the total brightness of the pixels in the image, covered with white feature cells, andB is the total brightness of the pixels covered with black feature cells.

Some examples of the most popular Haar features are given below.

Your task is to determine the number of operations that are required to calculate the feature by using the so-calledprefix rectangles.

A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.

You have a variable value, whose value is initially zero. In oneoperation you can count the sum of pixel values at any prefix rectangle, multiply it by any integer and add to variablevalue.

You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.

,开上一部车,装着我们的故事,

CodeForces 549D (暴力、模拟)

相关文章:

你感兴趣的文章:

标签云: