HDU1510 White rectangles
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
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的更多相关文章
- HDU1510 White rectangles( 乱搞 O(n^3) )题解
思路: 友谊赛的时候一直想到了,但是没想出来怎么遍历才能找到所有矩阵,卡住了. 这里讲一下完整思路:我们用一个num[i][j]表示第i行第j列每一列连续的白色格子数量,然后我们定义一个MIN,并且每 ...
- White Rectangles[HDU1510]
White Rectangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 【HDOJ】1510 White Rectangles
这个题目很好,变形的题目也很多.简单DP. /* 1510 */ #include <cstdio> #include <cstring> #include <cstdl ...
- zoj 2067 White Rectangles
这题解决的算法处理,真的很难想清楚!!尤其是最后的正矩形如何处理.不过终于看懂了 #include<stdio.h> #include<stdlib.h> #include&l ...
- PS网页设计教程XXIV——从头设计一个漂亮的网站
作为编码者,美工基础是偏弱的.我们可以参考一些成熟的网页PS教程,提高自身的设计能力.套用一句话,“熟读唐诗三百首,不会作诗也会吟”. 本系列的教程来源于网上的PS教程,都是国外的,全英文的.本人尝试 ...
- Gazebo機器人仿真學習探索筆記(三)機器人模型
gazebo_models:https://bitbucket.org/osrf/gazebo_models 模型庫下載,可以參考如下命令: ~/Rob_Soft/Gazebo7$ hg clone ...
- 【图像处理】Haar-like特征
特征提取的原理.代码等: 如果是白黑白,是减去一个黑的还是2个黑的,网上有不同的说法:应该需要看原论文了. 论文原文 The sum of the pixels which lie within th ...
- 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 ...
- woj1012 Thingk and Count DP好题
title: woj1012 Thingk and Count DP好题 date: 2020-03-12 categories: acm tags: [acm,dp,woj] 难题,dp好题,几何题 ...
随机推荐
- Axure RP 8.0正式版下载地址 安装和汉化说明
1.Axure RP和中文包包下载地址 官网地址:http://www.axure.com.cn/3510/ 2.下载完成后安装 3.破解 axure8.0注册码激活码:(亲测可用)用户名:aaa注册 ...
- 如何在安卓/data(而不是/data/data)目录下进行文件的读写操作
分析:Android默认是无法直接操作/data目录的,只能读写程序自己的私有目录,也就是/data/data/package name/下,默认只能操作这个目录下的文件,也就是我们想直接读写/dat ...
- .net 使用AjaxControlToolkit.dll 遇到的"Sys"未定义问题
1.配置文件一般都会缺少<httpHandlers></httpHandlers> 这一段, <httpHandlers> <remove verb=&quo ...
- google的西联汇款可以使用工行代收
- VMware Workstation 11序列号一枚
VMware Workstation 11序列号: 1F04Z-6D111-7Z029-AV0Q4-3AEH8
- Oracle 左连接、右连接、全外连接、(+)号作用、inner join(等值连接) (转载)
Oracle 外连接 (1)左外连接 (左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表都不加限制) 外连接(Outer Join) oute ...
- 解决UITabeleViewCell的分割线不能铺满问题
-(void)viewDidLayoutSubviews { if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)] ...
- 脚本学习python和linux-shell和jQuery(javascript)
使用脚本可以方便管理,使用计算机. 打算学脚本来更好地用计算机系统,特别是Linux. 学python因为它开源,而且是C家族的语言,本来也是课程需要,再加上它确实很好,所以非常主打,之前看过perl ...
- busybox下mount nfs的命令
busybox下mount nfs的命令 mount -f nfs -o nolock 10.130.30.2:/nfs/nuc970/rootfs /mnt/test
- 汇总前端最最常用的JS代码片段
html5选择器 //参数均接收一个合法的css选择器 element = document.querySelector('.foo,.bar');//返回带有foo或者bar样式类的首个元素 ele ...