White Rectangles

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 964    Accepted Submission(s): 485

Problem Description

You are given a chessboard made up of N squares by N squares with equal size. Some of the squares are colored black, and the others are colored white. Please write a program to calculate the number of rectangles which are completely made up of white squares.

Input

There are multiple test cases. Each test case begins with an integer N (1 <= N <= 100), the board size. The following N lines, each with N characters, have only two valid character values:
# - (sharp) representing a black square;
. - (point) representing a white square.
Process to the end of file.

Output

For each test case in the input, your program must output the number of white rectangles, as shown in the sample output.

Sample Input

2
.#
..
4
..#.
##.#
.#..
.#.#

Sample Output

5
15

Author

JIANG, Ming

Source

ZOJ Monthly, January 2004

Recommend

xhd   |   We have carefully selected several similar problems for you:  15001505150115061502

Statistic | Submit | Discuss | Note

没什么好说的,看代码。

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#define N 200
using namespace std; char square[N][N];
int dir[][] = {, , , , , }; //只定义右,下,右下方向可直接避免重复。
int cnt; void cal(int k, int i, int j, int n, int I, int J) {
int flag = ;
I = I + dir[k][];
J = J + dir[k][];
if(I >= n || J >= n) return;
for(int e = i; e <= I; e++) { //通过对角两个坐标做出矩形循环判断是否全是white square。
for(int k = j; k <= J; k++) {
if(square[e][k] == '#') {
flag = ;
break;
}
}
}
if(flag == ) {
cnt++;
if(k == ) {
for(int e = ; e < ; e++) { //朝左下方向时应该下一步应该3个方向都走。
cal(e, i, j, n, I, J);
}
} else cal(k, i, j, n, I, J);
} else return;
} void Function(int n) {
for(int i = ; i < n; i++) {
for(int j = ; j < n; j++) {
if(square[i][j] == '.') {
cnt++;
for(int k = ; k < ; k++) {
cal(k, i, j, n, i, j);
}
}
}
}
} int main() {
int n;
char c;
while(scanf("%d", &n) != EOF) {
cnt = ;
memset(&square, , sizeof(square));
for(int i = ; i < n; i++) {
for(int j = ; j < n; j++)
cin >> square[i][j];
}
Function(n);
printf("%d\n", cnt);
}
return ;
}

HDU1510 White rectangles的更多相关文章

  1. HDU1510 White rectangles( 乱搞 O(n^3) )题解

    思路: 友谊赛的时候一直想到了,但是没想出来怎么遍历才能找到所有矩阵,卡住了. 这里讲一下完整思路:我们用一个num[i][j]表示第i行第j列每一列连续的白色格子数量,然后我们定义一个MIN,并且每 ...

  2. White Rectangles[HDU1510]

    White Rectangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. 【HDOJ】1510 White Rectangles

    这个题目很好,变形的题目也很多.简单DP. /* 1510 */ #include <cstdio> #include <cstring> #include <cstdl ...

  4. zoj 2067 White Rectangles

    这题解决的算法处理,真的很难想清楚!!尤其是最后的正矩形如何处理.不过终于看懂了 #include<stdio.h> #include<stdlib.h> #include&l ...

  5. PS网页设计教程XXIV——从头设计一个漂亮的网站

    作为编码者,美工基础是偏弱的.我们可以参考一些成熟的网页PS教程,提高自身的设计能力.套用一句话,“熟读唐诗三百首,不会作诗也会吟”. 本系列的教程来源于网上的PS教程,都是国外的,全英文的.本人尝试 ...

  6. Gazebo機器人仿真學習探索筆記(三)機器人模型

    gazebo_models:https://bitbucket.org/osrf/gazebo_models 模型庫下載,可以參考如下命令: ~/Rob_Soft/Gazebo7$ hg clone ...

  7. 【图像处理】Haar-like特征

    特征提取的原理.代码等: 如果是白黑白,是减去一个黑的还是2个黑的,网上有不同的说法:应该需要看原论文了. 论文原文 The sum of the pixels which lie within th ...

  8. Viola–Jones object detection framework--Rapid Object Detection using a Boosted Cascade of Simple Features中文翻译 及 matlab实现(见文末链接)

    ACCEPTED CONFERENCE ON COMPUTER VISION AND PATTERN RECOGNITION 2001 Rapid Object Detection using a B ...

  9. woj1012 Thingk and Count DP好题

    title: woj1012 Thingk and Count DP好题 date: 2020-03-12 categories: acm tags: [acm,dp,woj] 难题,dp好题,几何题 ...

随机推荐

  1. (转)PHP下编码转换函数mb_convert_encoding与iconv的使用说明

    之--http://www.jb51.net/article/21451.htm mb_convert_encoding这个函数是用来转换编码的.原来一直对程序编码这一概念不理解,不过现在好像有点开窍 ...

  2. 与数据库打交道的Adapter----SimpleCursorAdapter

    http://www.cnblogs.com/wenjiang/p/3196486.html 程序员是这个世界上最神奇的职业,因为几乎所有其他职业的人都能转到该行来,只要他智力正常,有接受过正规的编程 ...

  3. oracle - 创建数据库

    在服务器端的oracle,用户有点差异,当 我通过 'sqlplus / as sysdba' 命令登陆后,并不能创建数据库,sysdba拥有最高的系统权限,登陆后是 sys,以as sysdba登录 ...

  4. 如何设置MySQL Workbench EER Diagram 尺寸?

    ER Diagram -> Model -> Diagram Properties and Size...

  5. Template 模式

    Template 模式是很简单模式,但是也应用很广的模式.Template 是采用继承的方式实现算法的异构,其关键点就是将通用算法封装在抽象基类中,并将不同的算法细节放到子类中实现.Template ...

  6. SGU 190.Dominoes(二分图匹配)

    时间限制:0.25s 空间限制:4M 题意: 给定一个N*N的棋盘,一些格子被移除,在棋盘上放置一些1*2的骨牌,判定能否放满,并且输出任意方案. Solution: 首先考虑对棋盘的一个格子黑白染色 ...

  7. call/apply的第一个参数如果为null。this指向window

    call/apply是用来改变函数的作用域的,第一次参数为this,第二个参数为传输的值,例如 var a ="windowA"; var b = "windowB&qu ...

  8. ffmepg命令行参数

    ffmpeg使用 有些选项在每个流中都必须指定,例如比特率bitrate或编解码codec.指定流的字符串一般都会有各参数名称和参数,如编解码"-codec:a:1 ac3"表明第 ...

  9. 使用jQuery动态加载js脚本文件的方法

    动态加载Javascript是一项非常强大且有用的技术.这方面的主题在网上已经讨论了不少,我也经常会在一些个人项目上使用RequireJS和Dojo加载js 它们很强大,但有时候也会得不偿失.如果你使 ...

  10. redis运行状态图形化监控工具 — RedisLive

    在Centos中部署redis运行状态图形化监控工具 — RedisLive   写在前面 前两天看到张善友老师的一篇文章<先定个小目标, 使用C# 开发的千万级应用>,里面给出了一张腾讯 ...