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;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值