题目:https://codeforces.com/contest/549/problem/D

D. Haar Features
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

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.

Output

Print a single number — the minimum number of operations that you need to make to calculate the value of the feature.

Examples
Input

Copy
6 8
BBBBBBBB
BBBBBBBB
BBBBBBBB
WWWWWWWW
WWWWWWWW
WWWWWWWW
Output

Copy
2
Input

Copy
3 3
WBW
BWW
WWW
Output

Copy
4
Input

Copy
3 6
WWBBWW
WWBBWW
WWBBWW
Output

Copy
3
Input

Copy
4 4
BBBB
BBBB
BBBB
BBBW
Output

Copy
4
Note

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:

  1. 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);
  2. 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.

题意:

给你一个n*m的特征表格,每个格要么是B要么是W,现在你有一个全为0的n*m的表格,目标是使格中的值与特征表格对应,B对应-1,W对应1,
为了达成这个目标你有一个操作,可以在表格中选定一个坐标,使从表格左上角到这个坐标形成的矩形中的格都加上你想要加的一个数,
问为了达成目标的最少操作次数是多少

思路:

这个题在训练时硬是没看懂(语文英语水平太弱了...TAT),当时看题时就在想一些问题:1,这个操作到底是干什么的? 2.那个prefix rectangle是怎么样的?3.最后要达成的目标是什么?回答:1.这个操作是选一个坐标,使得表格左上角到这个坐标的数全都加上一个选定的数.2.一个prefix rectangle指的是矩形左上角固定在表格左上角,并得到到一个坐标作为右下角形成的矩形.3.把一个初始值为0的表格,通过最少次数的上面那种操作,使得表格中的值对应特征矩阵中B为-1,W为1(为什么???这个是Note里说的,Note也可以作为条件啊)考虑尽可能少的操作,因为prefix rectangle左上角固定了,我们可以从右下角开始逐行从右到左从下到上检测是否需要改变,这样就不会有无用的重复操作.

感觉这是一道英语阅读题...我太菜了TAT
 #include<bits/stdc++.h>
using namespace std;
const int amn=1e2+;
char mp[amn][amn];
int a[amn][amn];
int main(){
int n,m,ans,typ;
ios::sync_with_stdio();
while(cin>>n>>m){
memset(a,,sizeof a);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
cin>>mp[i][j];
}
}
ans=;
for(int i=n;i>=;i--){
for(int j=m;j>=;j--){
typ=((mp[i][j]=='W')?:-);
if(a[i][j]!=typ){
ans++;
for(int k=;k<=i;k++){
for(int l=;l<=j;l++){
a[k][l]+=typ-a[i][j];
}
}
}
}
}
printf("%d\n",ans);
}
}
/**
给你一个n*m的特征表格,每个格要么是B要么是W,现在你有一个全为0的n*m的表格,目标是使格中的值与特征表格对应,B对应-1,W对应1,
为了达成这个目标你有一个操作,可以在表格中选定一个坐标,使从表格左上角到这个坐标形成的矩形中的格都加上你想要加的一个数,
问为了达成目标的最少操作次数是多少
这个题在训练时硬是没看懂(语文英语水平太弱了...TAT),当时看题时就在想一些问题:1,这个操作到底是干什么的? 2.那个prefix rectangle是怎么样的?
3.最后要达成的目标是什么?
回答:
1.这个操作是选一个坐标,使得表格左上角到这个坐标的数全都加上一个选定的数.
2.一个prefix rectangle指的是矩形左上角固定在表格左上角,并得到到一个坐标作为右下角形成的矩形.
3.把一个初始值为0的表格,通过最少次数的上面那种操作,使得表格中的值对应特征矩阵中B为-1,W为1(为什么???这个是Note里说的,Note也可以作为条件啊)
考虑尽可能少的操作,因为prefix rectangle左上角固定了,我们可以从右下角开始逐行从右到左从下到上检测是否需要改变,这样就不会有无用的重复操作
感觉这是一道英语阅读题...我太菜了TAT
**/

[模拟,英语阅读] Codeforces 549D Haar Features的更多相关文章

  1. Codeforces 549D. Hear Features[贪心 英语]

    D. Haar Features time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  2. codeforces Looksery Cup 2015 D. Haar Features

    The first algorithm for detecting a face on the image working in realtime was developed by Paul Viol ...

  3. Looksery Cup 2015 D. Haar Features 暴力

    D. Haar Features Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/prob ...

  4. CF-weekly4 D. Haar Features

    https://codeforces.com/gym/253910/problem/D D. Haar Features time limit per test 1 second memory lim ...

  5. 英语阅读——Speaking Chinese in America

    这篇文章是<新视野大学英语>第四册的第五单元的文章,第一遍英语阅读完后对比中文,发现自己对作者的观点理解有些出入.作者反对的是认为中国说话客套而美国人直接的观点,利用自己的经历表达了中文也 ...

  6. 【模拟与阅读理解】Gym - 101954C Rullete

    http://codeforces.com/gym/101954/problem/C 题意:14行伪代码让你翻译. 坑得yibi #include<stdio.h> #include< ...

  7. 英语阅读——A meaningful life

    这篇文章是<新视野大学英语>第四册的第八单元的文章. 1 The death of an angel of animal rights activism(活动家) does not rat ...

  8. 英语阅读——The confusing pursuit of beauty

    这篇文章是<新视野大学英语>第四册的第二单元的文章,很好的一篇议论文,读起来也很有意思. 1 If you're a man, at some point a woman will ask ...

  9. 英语阅读——Love and logic:The story of a fallacy

    这篇文章是<新视野大学英语>第四册的第一单元的文章,读着挺有趣,便拿过来分享一下. 1 I had my first date with Polly after I made the tr ...

随机推荐

  1. PAT B1080 MOOC期终成绩(C++)

    PAT甲级目录 | PAT乙级目录 题目描述 B1080 MOOC期终成绩 解题思路 可利用 map 将字符串型的学号转换为整型的序号,方便查找.输入全部成绩后,遍历每个学生同时计算最终成绩,然后将成 ...

  2. 由uploadfive看servlet

    一.uploadfive的使用 上传工具是程序设计中最常用的功能,其中,uploadfive插件使用比较多,此处该插件进行文件的上传操作.该插件是基于HTML5的,因此PC端和移动端都可以使用. 使用 ...

  3. rsync 增量同步总是多两行数据

    从google云机器rsync日志到本地,并通过logstash格式化后存入elasticsearch,但在实施过程中发现,每次rsync后通过查看elasticsearch,都会将上次已同步的数据再 ...

  4. 用vue + leancloud开发一个免费的博客

    项目地址 https://github.com/Fee-ing/Fe... 在线预览 在线预览地址: 搭建免费博客

  5. css手写一个表头固定

    Bootstrap,layui等前端框架里面都对表头固定,表格滚动有实现,偏偏刚入职的公司选择了手动渲染表格,后期又觉得表格数据拉太长想要做表头固定.为了避免对代码改动太大,所以决定手写表头固定 主要 ...

  6. html+css+js+Hbuilder开发一款安卓APP,根本不用学Android开发!

    我们知道,要做一款安卓APP,咱们得先学安卓开发语言,例如java,前端后端.那么没有这些开发语言基础,咱们怎么做呢?其实现在有比较好的开发方案就是做webAPP,咱们可以用web前端知识构建安卓客户 ...

  7. 关于Html+css阶段学习总结

    一.学习经历 进入大学不久,就加入了社团,从而对前端有了一个初步的了解,之后也做过一些学校的官网,积累了一些微小的经验. 到了大二的时候,学校开设了专门的html+css课程,从中也学到许多新的htm ...

  8. Spring Cloud Feign 优雅的服务调用

    Fegin 是由NetFlix开发的声明式.模板化HTTP客户端,可用于SpringCloud 的服务调用.提供了一套更优雅.便捷的HTTP调用API,并且SpringCloud整合了Fegin.Eu ...

  9. 《即时消息技术剖析与实战》学习笔记11——IM系统如何保证服务高可用:流量控制和熔断机制

    IM 系统的不可用主要有以下两个原因: 一是无法预测突发流量,即使进行了服务拆分.自动扩容,但流量增长过快时,服务已经不可用了: 二是业务中依赖的这些接口.资源不可用或变慢时,比如发消息可能需要依赖& ...

  10. 数据加密标准(DES)详解

    1 简介 1.1 历史 DES(Data Encryption Standard)是由IBM公司在1974年提出的加密算法,在1977年被NIST定位数据加密标准.随后的很多年里,DES都是最流行的对 ...