博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Looksery Cup 2015 D. Haar Features 暴力
阅读量:6758 次
发布时间:2019-06-26

本文共 3789 字,大约阅读时间需要 12 分钟。

D. Haar Features

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/549/problem/D

Description

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.

Sample Input

6 8

BBBBBBBB
BBBBBBBB
BBBBBBBB
WWWWWWWW
WWWWWWWW
WWWWWWWW

Sample Output

2

HINT

题意

每次都会使一个前缀矩阵加上任意数,然后问你最小操作数

题解:

数据范围很小,所以直接暴力就好了

代码:

 

//qscqesze#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define test freopen("test.txt","r",stdin) #define maxn 2000001#define mod 10007#define eps 1e-9int Num;char CH[20];const int inf=0x3f3f3f3f;const ll infll = 0x3f3f3f3f3f3f3f3fLL;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}inline void P(int x){ Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts("");}//**************************************************************************************string s[110];int a[110][110];int b[110][110];int main(){ int n=read(),m=read(); for(int i=0;i
>s[i]; for(int i=0;i
=0;i--) { for(int j=m-1;j>=0;j--) { if(a[i][j]!=b[i][j]) { for(int k=0;k<=i;k++) { for(int m=0;m<=j;m++) { a[k][m]+=b[i][j]-a[i][j]; } } ans++; } } } cout<
<

 

 

 

转载地址:http://rvweo.baihongyu.com/

你可能感兴趣的文章
生产环境linux服务器系统安全配置
查看>>
我的友情链接
查看>>
MySql中 delimiter 详解
查看>>
浏览器history操作实现一些功能
查看>>
你那么喜欢看”干货“,是因为你根本不想下功夫。
查看>>
软件测试用例
查看>>
python mysql 单表查询 多表查询
查看>>
android handler概念解释
查看>>
eclipse代码左虚线对齐设置
查看>>
插入排序的Java代码实现
查看>>
Spring整合Web开发
查看>>
在SContruct中编译.c
查看>>
让ubuntu开启ssh服务以及让vi/vim正常使用方向键与退格键
查看>>
10.两个链表的交叉
查看>>
Visio Premium 2010密钥+破解激活方法
查看>>
JEE , EJB概念深入概括
查看>>
socket通信简单介绍
查看>>
Unity3D逻辑热更新,第二代舒爽解决方案,L#使用简介
查看>>
状态码表
查看>>
产品经理:想爱没那么简单
查看>>