CF 549D. Haar Features(神奇,不知道怎么推出来的)
来源:互联网 发布:有没有连环画软件 编辑:程序博客网 时间:2024/05/01 15:30
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 computes Haar 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 size n × 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 of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B 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-called prefix 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 one operation you can count the sum of pixel values at any prefix rectangle, multiply it by any integer and add to variable value.
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.
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100) — the number of rows and columns in the feature.
Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
Print a single number — the minimum number of operations that you need to make to calculate the value of the feature.
6 8BBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWW
2
3 3WBWBWWWWW
4
3 6WWBBWWWWBBWWWWBBWW
3
4 4BBBBBBBBBBBBBBBW
4
The first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations:
- add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame);
- add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient - 2 and variable value.
Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 = - 1, as required.
http://codeforces.com/contest/549/problem/D
#include<stdio.h>int n,m;char a[106][106];int b[106][106];int ans;int main(){int i,j;scanf("%d%d",&n,&m);for(i=0;i<n;i++){scanf("%s",a[i]);}for(i=0;i<n;i++){for(j=0;j<m;j++){if(a[i][j]=='W')b[i][j]=1;else b[i][j]=-1;}}ans=0;for(i=0;i<n;i++){for(j=0;j<m;j++){if(b[i][j]+b[i+1][j+1]!=b[i][j+1]+b[i+1][j])ans++;}}printf("%d",ans);}
- CF 549D. Haar Features(神奇,不知道怎么推出来的)
- codeforces 549D D. Haar Features(枚举)
- Codeforces 549D Haar Features (模拟)
- 不知道积分是怎么来的
- CodeForces 549D Haar Features 矩形成图
- codeforces Looksery Cup 2015 D. Haar Features
- Looksery Cup 2015 D. Haar Features
- bzoj1192(数学,真不知道自己怎么做出来的)
- 神奇的读心术。。。不知道怎么回事?
- 哈尔特征(Haar-like features)
- 好心人来帮忙哈~ C++的一道题不知道怎么做了
- 我自己都不知道怎么写出来的了 太可怕了 js
- 细说伟哥那些你不知道的神奇用途
- ::不知道怎么转的贴子::
- 不知道怎么了???
- 不知道怎么
- 不知道怎么写
- 我不知道我怎么了。。。。最近一年里不知道自己是怎么度过的。。。。。
- 菜鸟学排序算法
- 分享:15个有趣的大数据经济指数
- #306 (div.2) D. Regular Bridge
- c++公用数据的保护
- hdu5233 Gunner II
- CF 549D. Haar Features(神奇,不知道怎么推出来的)
- quick-cocos2d-x如何在mac下编译安卓版本
- 第七章
- 使用Unversial-image-loader来异步加载网络图片和本地图片(二)完结篇
- 点击按钮切换图片
- 关于mexfuntion超级好的输入输出总结
- 第3题
- vs2010中添加qt的对话框
- STL学习笔记之迭代器--iterator(源码剖析)