题目: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. 01Java代码是怎么运行的

    从虚拟机视角来看,执行 Java 代码首先需要将它编译而成的 class 文件加载到 Java 虚拟机中.加载后的 Java 类会被存放于方法区(Method Area)中.实际运行时,虚拟机会执行方 ...

  2. 在没有APP的125年前 印度的外卖小哥是这样送餐

    说到印度,你想到的是什么?咖喱.歌舞剧.开挂的火车?通通不是,我今天要说的是他们的外卖小哥,在印度如同"神"一般的存在.其实印度人不叫这批人为外卖小哥,而称他们为dabbawala ...

  3. Presto单机/集群模式安装笔记

    Presto单机/集群模式安装笔记 一.安装环境 二.安装步骤 三.集群模式安装: 3.1 集群模式修改配置部分 3.1.1 coordinator 节点配置. Node172配置 3.1.2 nod ...

  4. C++走向远洋——38(用对象数组操作长方柱类)

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:changfangzhu.cpp * 作者:常轩 * 微信公众号 ...

  5. openpyxl(python操作Excel)

    一.安装 >>> pip install openpyxl import openpyxl 二.常用操作 1.创建与保存一个工作簿 wb = openpyxl.Workbook() ...

  6. sklearn简单实现机器学习算法记录

    sklearn简单实现机器学习算法记录 需要引入最重要的库:Scikit-learn 一.KNN算法 from sklearn import datasets from sklearn.model_s ...

  7. go语言指南之斐波纳契闭包

    练习:斐波纳契闭包 让我们用函数做些好玩的事情. 实现一个 fibonacci 函数,它返回一个函数(闭包),该闭包返回一个斐波纳契数列 `(0, 1, 1, 2, 3, 5, ...)`. 这是一个 ...

  8. 使用Pods中使用Swift和Objective-C混编-编译不通过的原因

    iOS开发#使用Pods中使用Swift和Objective-C混编-编译不通过的原因-ld: symbol(s) not found for architecture arm64 问题基本描述 在P ...

  9. Linux-基本操作(登入登出,图形化界面,命令行界面)

    命令行界面登录 (1)命令行登录界面 安装好Centos后,系统启动默认进入的是图形化界面,可以通过如下命令修改进入命令行界面: 命令行登录:systemctl  set-default  multi ...

  10. vue+element 表单封成组件(1)

    作为一名刚接触vue不到一个月的菜鸟,思想还没有从操作DOM转变为数据驱动,看vue的代码处处别扭.组里为了让我熟悉vue交给了我一个将element 表单封装成组件的练手任务.由于开发过程中遇到的表 ...