hdu 5538(水)

Input
The first line contains an integer  T  indicating the total number of test cases.
First line of each test case is a line with two integers  n,m .
The  n  lines that follow describe the array of Nyanko-san's blueprint, the  i -th of these lines has  m  integers  ci,1,ci,2,...,ci,m , separated by a single space.

1T50
1n,m50
0ci,j1000
 

Output
For each test case, please output the number of glass units you need to collect to meet Nyanko-san's requirement in one line.
 

Sample Input
   
   
   
   
2 3 3 1 0 0 3 1 2 1 1 0 3 3 1 0 1 0 0 0 1 0 1
 

Sample Output
   
   
   
   
30 20


题意:给你n*m的地方,每个点有一个数组x代表这的高度,求这个立体的表面积

思路:求出顶部面积,在计算每个柱子比周围柱子高多少即可


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;

int tmap[55][55];
int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

int main()
{
    int T,n,m;
    scanf("%d",&T);
    while(T--)
    {
        ll ans = 0;
        scanf("%d%d",&n,&m);
        memset(tmap,0,sizeof(tmap));
        for(int i = 1; i <= n; i ++)
            for(int j = 1; j <= m; j++)
            {
                scanf("%d",&tmap[i][j]);
                if(tmap[i][j] > 0)
                    ans ++;
            }
        for(int i = 1; i <= n; i ++)
            for(int j = 1; j <= m; j++)
            {
                for(int k = 0;k < 4;k++)
                {
                    int tx = i+dir[k][0];
                    int ty = j+dir[k][1];
                    if(tmap[i][j] > tmap[tx][ty])
                        ans += tmap[i][j] - tmap[tx][ty];
                }
            }
            printf("%lld\n",ans);
    }
    return 0;
}




你可能感兴趣的:(HDU)