ZOJ 2067 HDU 1510 white rectangles

Source: Internet
Author: User
Tags min time limit
White rectangles time Limit:2 Seconds Memory limit:65536 KB You is given a chessboard made up of n squares by N sq Uares with equal size. Some of the squares are colored black, and the others is colored white. Please write a program to calculate the number of rectangles which is completely made up of white squares.


Input

There is multiple test cases. Each test case is begins with an integer n (1 <= n <=), the board size. The following n lines, each with N characters, has only a 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 the white rectangles, as shown in the sample output.


Sample Input

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


Sample Output

5
15

#include <stdio.h>
#include <string.h>
#define MAX
#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 Column 1 column judgment middle break end 
			{
				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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.