[Hdu5538] [5acm/ICPC Changchun station in Asia] House Building Question & code
Question:
In the top view of the building block chart, input data indicates that (I, j) is placed with a building block with the height of h [I] [j, calculate the surface area (not the lower surface !!!).
Question:
A question, such as me, can quickly think of a question... See the code implementation for details.
Code:
#include
#include#include
#include
using namespace std;int T,n,m,h[55][55];int main(){ scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); memset(h,0,sizeof(h)); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) scanf("%d",&h[i][j]); int ans=0; for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) { if (h[i][j]!=0) ans++; if (h[i][j]>h[i-1][j]) ans+=h[i][j]-h[i-1][j]; if (h[i][j]>h[i+1][j]) ans+=h[i][j]-h[i+1][j]; if (h[i][j]>h[i][j-1]) ans+=h[i][j]-h[i][j-1]; if (h[i][j]>h[i][j+1]) ans+=h[i][j]-h[i][j+1]; //cout<