题意:求给出图的表面积,不包括底面
///1085422276 #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=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘) { if(ch==‘-‘)f=-1; ch=getchar(); } while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘; ch=getchar(); } return x*f; } //**************************************** #define maxn 100+5 int ss[4][2]={-1,0, 0,-1, 1,0, 0,1}; int a[maxn][maxn],n,m; bool check(int x,int y){ if(x<=0||y<=0||x>n||y>m)return 1; else return 0; } int main(){ int T; scanf("%d",&T); while(T--){ mem(a); ll sum=0; ll tmp=0; ll ans=0; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%d",&a[i][j]); if(a[i][j]) tmp=tmp+(a[i][j]-1); sum+=a[i][j]; if(a[i][j])ans++; } } sum*=6; sum-=ans; ans=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(a[i][j]!=0) for(int k=0;k<4;k++){ int xx=i+ss[k][0]; int yy=j+ss[k][1]; 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/=2; ans+=tmp; ans*=2; //cout<<ans<<endl; sum=sum-ans; printf("%I64d\n",sum); } return 0; }
代码
时间: 2024-10-04 17:12:10