ZOJ 2067 White Rectangles

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

 

 

 1 #include <stdio.h>
 2 #include <string.h>
 3 int n;
 4 char g[102][102];
 5 int f[102][102];
 6 
 7 int main(int argc, char *argv[])
 8 {
 9     while( scanf("%d",&n)!=EOF ){
10         for(int i=1; i<=n; i++){
11             getchar();
12             for(int j=1; j<=n; j++){
13                 scanf("%c" ,&g[i][j]);
14             }
15         }
16         memset(f,0,sizeof(f));
17         for(int i=1; i<=n; i++){
18             for(int j=1; j<=n; j++){
19                 if(g[i][j]=='.')
20                     f[i][j]=f[i][j-1]+1;
21             }
22         }
23         int ans=0;
24         for(int i=1; i<=n; i++){
25             for(int j=1; j<=n; j++){
26                 int cur=f[i][j];
27                 if(cur==0)continue;
28                 int cnt=0;
29                 int min=cur;
30                 while(cnt+i<=n){
31                     if(min<=0){
32                         break;                    
33                     }else{
34                         if(f[i+cnt][j]<min)
35                             min=f[i+cnt][j];
36                         ans+=min;
37                     }
38                     cnt++;
39                 }
40             }
41         }
42         printf("%d\n",ans);    
43     }    
44     return 0;
45 }

 

转载于:https://www.cnblogs.com/chenjianxiang/p/3616591.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值