ZOJ 2067 HDU 1510 White Rectangles

White Rectangles

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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

#include <stdio.h>
#include <string.h>
#define MAX 110
#define inf 0x7fffffff
char a[MAX][MAX];
int count[MAX][MAX];
int n;

int min(int x,int y)
{
	return x<y?x:y;
}

void sum()
{
	int i,j;
	for(i = 1;i <= n; i++)
	{
		for(j = 1;j <= n; j++)
		{
			if(a[i][j] == '.')
			{
				count[i][j] = count[i][j - 1] + 1; 
			}
		}
	}
}

int Min()
{
	int i,j,k;
	int ans = 0;
	for(i = 1;i <= n; i++)
	{
		for(j = 1;j <= n; j++)
		{
			int m = inf;
			for(k = i;k <= n && count[k][j]; k++)//1列1列判断 中间断了结束 
			{
				m = min(m,count[k][j]);
				ans += m;
			}
		}
	}
	return ans;
}
int main()
{
	int i;
	while(scanf("%d",&n)!=EOF)
	{
		for(i = 1;i <= n; i++)
			scanf("%s",a[i] + 1);
		memset(count,0,sizeof(count));
		sum();
		printf("%d\n",Min());
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值