题意:求给出图的表面积,不包括底面
///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define inf 100000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//****************************************
#define maxn 100+5
int ss[][]={-,, ,-, ,, ,};
int a[maxn][maxn],n,m;
bool check(int x,int y){
if(x<=||y<=||x>n||y>m)return ;
else return ;
}
int main(){ int T;
scanf("%d",&T);
while(T--){
mem(a);
ll sum=;
ll tmp=;
ll ans=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf("%d",&a[i][j]);
if(a[i][j])
tmp=tmp+(a[i][j]-);
sum+=a[i][j];
if(a[i][j])ans++;
}
}
sum*=;
sum-=ans;
ans=; for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(a[i][j]!=)
for(int k=;k<;k++){
int xx=i+ss[k][];
int yy=j+ss[k][];
if(check(xx,yy))continue;
if(a[xx][yy]) {ans+=(min(a[i][j],a[xx][yy]));}
}
}
}
// cout<<sum<<endl;
//cout<<ans/2+tmp<<endl;
ans/=;
ans+=tmp;
ans*=;
//cout<<ans<<endl;
sum=sum-ans;
printf("%I64d\n",sum);
}
return ;
}
代码