[模拟,英语阅读] 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 ...
随机推荐
- Redis过期key淘汰策略
Redis采用惰性+定期的key淘汰策略 1. Redis配置项hz定义了serverCron任务的执行周期,默认为10,即CPU空闲时每秒执行10次; 2. 每次过期key清理的时间不超过CPU时间 ...
- 5G-NR物理信道与调制-下行链路v1.1.0
上接<5G-NR物理信道与调制v1.1.0>下行链路 References Definitions, symbols and abbreviations 帧结构与物理资源 通用函数 上行链 ...
- 如何安装及使用honmaple社区程序 · honmaple's blog · 风落花语风落天,花落风雨花落田.
Table of Contents 1. 如何安装及使用 1.1. 安装需要的package 1.2. 配置config 1.3. 注释下面代码 1.4. 初始化数据库 1.5. 创建管理员账户 2. ...
- QIs for Spread
玩了好几天,看了好多剧,所以这几天的进度稍微有点慢,另外,<一起同过窗>真香! 延展特性涉及解集覆盖的区域.一个具有良好分布的解集应该包含来自PF每个部分的解集,而不遗漏任何区域.然而,大 ...
- sys.argv的意义[转]
sys.argv的意义 原文地址:https://www.cnblogs.com/zzliu/p/10775049.html 简单来说,sys.argv是一个参数列表,这个列表存放着从外界获取到的参数 ...
- LeetCode 题解 | 1. 两数之和
题目描述: 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, 15], t ...
- Linux - 修改系统的max open files、max user processes(附ulimit的使用方法)【转载】
Linux - 修改系统的max open files.max user processes(附ulimit的使用方法)目录 1 问题说明2 修改max open files3 修改max user ...
- springmvc两种配置方法
基于配置文件xml方式, 配置springmvc步骤: 1.在pom文件中引入jar包: <!--导入springmvc的jar包--> <dependency> <gr ...
- 小白学 Python 数据分析(13):Pandas (十二)数据表拼接
人生苦短,我用 Python 前文传送门: 小白学 Python 数据分析(1):数据分析基础 小白学 Python 数据分析(2):Pandas (一)概述 小白学 Python 数据分析(3):P ...
- 37个JavaScript基本面试问题和解答
1.使用typeof bar ==="object"来确定bar是否是一个对象时有什么潜在的缺陷?这个陷阱如何避免? 尽管typeof bar ==="object&qu ...