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好题,几何题 ...
随机推荐
- c#迭代算法
//用迭代算法算出第m个值 //1,1,2,3,5,8...; //{1,0+1,1+1,1+2,2+3 ,3+5} static void Main(string[] arg ...
- jQuery AJAX实现调用页面后台方法
1.新建demo.aspx页面.2.首先在该页面的后台文件demos.aspx.cs中添加引用. using System.Web.Services; 3.无参数的方法调用. 大家注意了,这个版本不能 ...
- Web性能压力测试之Webbench使用详解
Webbench是知名的网站压力测试工具,它是由Lionbridge公司(http://www.lionbridge.com)开发.Webbench能测试处在相同硬件上,不同服务的性能以及不同硬件上同 ...
- 我的第一个boke
哈哈哈 接口
- hdoj 2191(多重背包)
悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/ ...
- JavaMail API 1.4.7邮件发送
下载oracle javaMail API: http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive- ...
- location传值
location.href="url?p="+"value"; onclick="location.href='Card_query_where?qu ...
- psql rank row
rank() OVER (PARTITION BY f1 ORDER BY f2 DESC) ROW_NUMBER() () OVER (PARTITION BY f1 ORDER BY f2 DES ...
- Python Lib:pyzmq
http://git.oschina.net/gitlab/StartWithCoding/tree/master/example/python/pyzmq
- 使用java求高精度除法,要求保留N位小数
题目要求是高精度除法,要求保留N位小数(四舍五入),并且当整数部分为0时去除0的显示 import java.math.BigDecimal; import java.util.Scanner; pu ...