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. SQL server 如何修改登录名和密码

    No :1 启动SQL Server Management Studio,用windows登录进入: No :2 在左侧对象资源处理器中找到根节点,也就是你安装sqlserver时注册的服务器名称.然 ...

  2. OC - 22.隐式动画

    简介 每个UI控件,默认自动创建一个图层(根图层),即每个UI控件对应于至少一个图层 每一个UIView内部都默认关联着一个CALayer,我们可用称这个Layer为Root Layer(根层)   ...

  3. php学习小技巧

    1.print_r可打印数组 <?php echo '<p class="ajax">This paragraph was loaded with AJAX.&l ...

  4. asp.net MVC 从其它项目复制过来的Area里面的Controllers文件读取不到

    从其实项目复制过来的Controllers,在访问时显示不存在文件 检查一下对应的area里面的AreaRegistration文件的命名空间是否一致

  5. 干掉Google字体,WordPress速度暴涨

    2014年7月7日23:40:31 因为Google被墙,WordPress引用的Google字体总会加载很长时间,严重影响打开速度. 安装WordPress插件 Disable Google Fon ...

  6. nginx 一般配置实例 静态页面

    # 使用的用户和组 user www www; # 指定工作衍生进程数(一般等于CPU的总核数或总核数的两倍,例如两个四核CPU,则总核数为8) worker_processes 8; # 指定错误日 ...

  7. YII Query Builder

    今天遇到一个Query Builder 联合查询问题: 查询关联表某个字段的总数

  8. python中去掉空行的问题

    在python中处理空行时,经常会遇到一些问题.现总结经验如下: 1.遇到的空行如果只有换行符,直接使用=='\n'或者 len(line)==line.count('\n') 2.有多个空格+换行符 ...

  9. BZOJ 3570 动物园

    Description 近日,园长发现动物园中好吃懒做的动物越来越多了.例如企鹅,只会卖萌向游客要吃的.为了整治动物园的不良风气,让动物们凭自己的真才实学向游客要吃的,园长决定开设算法班,让动物们学习 ...

  10. [HDOJ 5155] Harry And Magic Box

    题目链接:HDOJ - 5155 题目大意 有一个 n * m 的棋盘,已知每行每列都至少有一个棋子,求可能有多少种不同的棋子分布情况.答案对一个大素数取模. 题目分析 算法1: 使用容斥原理与递推. ...