[模拟,英语阅读] Codeforces 549D Haar Features
题目:https://codeforces.com/contest/549/problem/D
1 second
256 megabytes
standard input
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.
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 8
BBBBBBBB
BBBBBBBB
BBBBBBBB
WWWWWWWW
WWWWWWWW
WWWWWWWW
2
3 3
WBW
BWW
WWW
4
3 6
WWBBWW
WWBBWW
WWBBWW
3
4 4
BBBB
BBBB
BBBB
BBBW
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.
题意:
给你一个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的更多相关文章
- Codeforces 549D. Hear Features[贪心 英语]
D. Haar Features time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 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 ...
- Looksery Cup 2015 D. Haar Features 暴力
D. Haar Features Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/prob ...
- CF-weekly4 D. Haar Features
https://codeforces.com/gym/253910/problem/D D. Haar Features time limit per test 1 second memory lim ...
- 英语阅读——Speaking Chinese in America
这篇文章是<新视野大学英语>第四册的第五单元的文章,第一遍英语阅读完后对比中文,发现自己对作者的观点理解有些出入.作者反对的是认为中国说话客套而美国人直接的观点,利用自己的经历表达了中文也 ...
- 【模拟与阅读理解】Gym - 101954C Rullete
http://codeforces.com/gym/101954/problem/C 题意:14行伪代码让你翻译. 坑得yibi #include<stdio.h> #include< ...
- 英语阅读——A meaningful life
这篇文章是<新视野大学英语>第四册的第八单元的文章. 1 The death of an angel of animal rights activism(活动家) does not rat ...
- 英语阅读——The confusing pursuit of beauty
这篇文章是<新视野大学英语>第四册的第二单元的文章,很好的一篇议论文,读起来也很有意思. 1 If you're a man, at some point a woman will ask ...
- 英语阅读——Love and logic:The story of a fallacy
这篇文章是<新视野大学英语>第四册的第一单元的文章,读着挺有趣,便拿过来分享一下. 1 I had my first date with Polly after I made the tr ...
随机推荐
- Dubbo源码学习(二)
@Adaptive注解 在上一篇ExtensionLoader的博客中记录了,有两种扩展点,一种是普通的扩展实现,另一种就是自适应的扩展点,即@Adaptive注解的实现类. @Documented ...
- 「知乎」对中国用户而言,Pure Android 是否比 MIUI 或 Flyme 体验更好? - Donnie的博客
这篇文章转载自我在知乎上的回答 哎呀-不要站队嘛.其实这是一个很有意思的题目,让我们一点点来看 哦对,谢妖-.本人是Nexus 5用户,系统当然是Pure Android KitKat啦(臭谷粉!点D ...
- tcpdump常用方法
tcpdump -i eth0监视制定网络接口的数据包 tcpdump host 10.13.1.135监视所有10.13.1.135主机收到和发出的数据包 tcpdump src host 10.1 ...
- python3.5以及scrapy,selenium,等 安装
一.python3.5安装和配置 在安装的时候无意间发现了,python3.6没有给我自定义安装的机会,直接就C盘见:因此我选择了python3.5.<安装部分跳过,至于一条吃过痛苦的建议:不要 ...
- Hibernate和Mybatis的工作原理以及区别
一.Mybatis的工作流程图 (1).原理详见: MyBatis应用程序根据XML配置文件创建SqlSessionFactory,SqlSessionFactory在根据配置,配置来源于两个地方,一 ...
- 车道线检测LaneNet
LaneNet LanNet Segmentation branch 完成语义分割,即判断出像素属于车道or背景 Embedding branch 完成像素的向量表示,用于后续聚类,以完成实例分割 H ...
- 【Amaple教程】5. 插件
Amaple 拥有非常强大插件功能,这也是它的突出功能之一,Amaple插件一般表现为功能块(函数)或功能块(包含一系列函数和属性的Object对象),它除了支持Amaple规范定义的插件外,还支持所 ...
- Python——工厂模式
目录 前言 一.简单工厂 二.工厂方法 抽象工厂 结论 参考 前言 工厂模式,顾名思义就是我们可以通过一个指定的"工厂"获得需要的"产品". 在设计模式中主要用 ...
- 编码的来源于格式简介ANSI、GBK、GB2312、UTF-8、GB18030和 UNICODE
编码一直是让新手头疼的问题,特别是 GBK.GB2312.UTF-8 这三个比较常见的网页编码的区别,更是让许多新手晕头转向,怎么解释也解释不清楚.但是编码又是那么重要,特别在网页这一块.如果你打出来 ...
- nes 红白机模拟器 第7篇 编译使用方法
模拟器,基于 InfoNES ,作者添加修改以下功能: 1, joypad 真实手柄驱动程序(字符型设备驱动) 2,原始图像只有256*240 ,添加 图像放大算法,这里实现了2种,a, 最近邻插值 ...