Topic Links:
HDU 5538 House Building House Building
Title: Given a top view of a building block, and the height of each coordinate block, calculate the surface area of the entire stereoscopic map (excluding the bottom surface area).
Problem-Solving ideas: Add a frame to a given top view, and compare each point of the top view with the top and bottom of each point to calculate the increment (height difference).
Input
The first line contains a integer T indicating the total number of test cases.
First line of all test case was a line with the integers n,m.
The n lines that follow describe the array of Nyanko-san ' s blueprint, the i-th of these lines have m integers ci,1,ci,2,..., c I,m, separated by a single space.
1≤t≤50
1≤n,m≤50
0≤ci,j≤1000
Output
For each test case, please output the number of glass units you need to collect to meet Nyanko-san ' s requirement in one Li Ne.
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
#include <iostream> #include <cstdio> #include <cstring> using namespace std;
int main () {int k,n,m,i,j,area[4],sum,ans;
int a[101][101];
scanf ("%d", &k);
while (k--) {ans=0;
scanf ("%d%d", &n,&m);
for (i=0;i<=n+1;i++) for (j=0;j<=m+1;j++) a[i][j]=0;//increase the border, put each clears 0 for (i=1;i<=n;i++)
for (j=1;j<=m;j++) scanf ("%d", &a[i][j]);
for (i=1;i<=n;i++) {for (j=1;j<=m;j++) {sum=0;
if (a[i][j]!=0) {if (a[i][j]>a[i][j-1]) area[0]=a[i][j]-a[i][j-1];
else area[0]=0;
if (a[i][j]>a[i][j+1]) area[1]=a[i][j]-a[i][j+1];
else area[1]=0;
if (A[i][j]>a[i-1][j]) area[2]=a[i][j]-a[i-1][j];
else area[2]=0; if (a[i][J]>A[I+1][J]) area[3]=a[i][j]-a[i+1][j];
else area[3]=0;
sum=area[0]+area[1]+area[2]+area[3]+1;//Calculate the height difference ans=ans+sum;
}}} printf ("%d\n", ans);
} return 0;
}