HDU5538 House Building(简单计算)

本文介绍了一种遍历每个数并计算其四个面表面积的方法来解决计算表面积的问题。通过实例代码演示了如何使用C++实现这一算法。

题目链接
题意:计算表面积。
解法:遍历每一个数,计算4个面的表面积。


#include<cstdio>
#include<algorithm>
#include<cstring>
//#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define X first
#define Y second
#define cl(a,b) memset(a,b,sizeof(a))
typedef pair<long long ,long long > P;
const int maxn=55;
const LL inf=1LL<<45;
const LL mod=1e9+7;
int dir[][2]={1,0,0,-1,0,1,-1,0};
int a[maxn][maxn];
int main(){
    int T;scanf("%d",&T);
    while(T--){
        int n,m;
        scanf("%d%d",&n,&m);
        cl(a,0);
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                scanf("%d",&a[i][j]);
            }
        }
        int sum=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++)if(a[i][j]){
                int tmp=1;
                for(int k=0;k<4;k++){
                    int xx=i+dir[k][0];
                    int yy=j+dir[k][1];
                    if(a[i][j]>a[xx][yy]){
                        tmp+=a[i][j]-a[xx][yy];
                    }
                }
                sum+=tmp;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值